CRUDlexTests\MySQLDataTest::testFetchReferences PHP Method

testFetchReferences() public method

public testFetchReferences ( )
    public function testFetchReferences()
    {
        $entityLibrary = $this->dataLibrary->createEmpty();
        $entityLibrary->set('name', 'lib');
        $this->dataLibrary->create($entityLibrary);
        $entityBook = $this->dataBook->createEmpty();
        $entityBook->set('title', 'title');
        $entityBook->set('author', 'author');
        $entityBook->set('pages', 111);
        $entityBook->set('library', $entityLibrary->get('id'));
        $entityBook->set('secondLibrary', $entityLibrary->get('id'));
        $this->dataBook->create($entityBook);
        $read = $entityBook->get('library');
        $expected = '1';
        $this->assertSame($read, $expected);
        $books = [$entityBook];
        $this->dataBook->fetchReferences($books);
        $read = $books[0]->get('library');
        $expected = ['id' => '1', 'name' => 'lib'];
        $this->assertSame($read, $expected);
        $read = $books[0]->get('secondLibrary');
        $expected = ['id' => '1'];
        $this->assertSame($read, $expected);
        $nullBooks = null;
        $this->dataBook->fetchReferences($nullBooks);
        $emptyBooks = [];
        $this->dataBook->fetchReferences($emptyBooks);
    }