RedUNIT\Base\Foreignkeys::testFKInspect PHP Method

testFKInspect() public method

Tests foreign keys but checks using ProxyWriter.
public testFKInspect ( ) : void
return void
    public function testFKInspect()
    {
        $faultyWriter = new \FaultyWriter(R::getDatabaseAdapter());
        try {
            $null = \ProxyWriter::callMethod($faultyWriter, 'getForeignKeyForTypeProperty', 'test', 'test');
            pass();
        } catch (\Exception $e) {
            fail();
        }
        asrt(is_null($null), TRUE);
        $writer = R::getWriter();
        R::nuke();
        $book = R::dispense('book');
        $page = R::dispense('page');
        $book->xownPage[] = $page;
        R::store($book);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'book_id');
        asrt(is_array($keys), TRUE);
        asrt($keys['on_delete'], 'CASCADE');
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'id');
        asrt(is_null($keys), TRUE);
        R::nuke();
        $book = R::dispense('book');
        $page = R::dispense('page');
        $book->ownPage[] = $page;
        R::store($book);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'book_id');
        asrt(is_array($keys), TRUE);
        asrt($keys['on_delete'], 'SET NULL');
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'id');
        asrt(is_null($keys), TRUE);
        R::nuke();
        $book = R::dispense('book');
        $page = R::dispense('page');
        $book->alias('magazine')->xownPage[] = $page;
        R::store($book);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'magazine_id');
        asrt(is_array($keys), TRUE);
        asrt($keys['on_delete'], 'CASCADE');
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'book_id');
        asrt(is_null($keys), TRUE);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'page', 'id');
        asrt(is_null($keys), TRUE);
        R::nuke();
        $book = R::dispense('book');
        $page = R::dispense('page');
        $book->cover = $page;
        R::store($book);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book', 'cover_id');
        asrt(is_array($keys), TRUE);
        asrt($keys['on_delete'], 'SET NULL');
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book', 'page_id');
        asrt(is_null($keys), TRUE);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book', 'id');
        asrt(is_null($keys), TRUE);
        R::nuke();
        $book = R::dispense('book');
        $category = R::dispense('category');
        $book->sharedTag[] = $category;
        R::store($book);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book_category', 'book_id');
        asrt(is_array($keys), TRUE);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book_category', 'category_id');
        asrt(is_array($keys), TRUE);
        $keys = \ProxyWriter::callMethod($writer, 'getForeignKeyForTypeProperty', 'book_category', 'id');
        asrt(is_null($keys), TRUE);
    }