44
55class RepositoryAbstractTest extends PHPUnit_Framework_TestCase
66{
7- protected function setUp ()
7+ public function testSetAndGetStorageWithValidDataShouldWork ()
88 {
9- $ this ->entity = $ this ->getMock ('\WilliamEspindola\Field\Entity\EntityInterface ' );
10- $ this ->storage = $ this ->getMock ('\WilliamEspindola\Field\Storage\ORM\StorageORMInterface ' );
9+ $ storageAbstract = $ this ->getMock ('sdtClass ' , ['findAll ' ]);
1110
12- $ this ->storage ->expects ($ this ->any ())
13- ->method ('findAll ' )
14- ->will ($ this ->returnValue ([]));
11+ $ storage = $ this ->getMock ('\WilliamEspindola\Field\Storage\ORM\StorageORMInterface ' );
1512
16- $ this ->repository = new MockRepository ('tableName ' , $ this ->entity , $ this ->storage );
17- }
13+ $ storage ->expects ($ this ->any ())
14+ ->method ('__get ' )
15+ ->with ($ this ->equalTo ('storage ' ))
16+ ->will ($ this ->returnValue ($ storageAbstract ));
1817
19- /**
20- * @expectedException InvalidArgumentException
21- * @expectedExceptionMessage Invalid table name MockRepository.
22- */
23- public function testSetTableNameWidhInvalidDataShuldThrownAndException ()
24- {
25- $ this ->repository ->setTableName (1 );
26- }
18+ $ storage ->expects ($ this ->any ())
19+ ->method ('getRepository ' )
20+ ->will ($ this ->returnValue ($ storageAbstract ));
2721
28- public function testeSetTableNameWithValidDataShouldWork ()
29- {
30- $ this ->repository ->setTableName ('ola ' );
31- $ this ->assertEquals ('ola ' , PHPUnit_Framework_Assert::readAttribute ($ this ->repository , 'tableName ' ));
32- }
22+ $ repository = new MockRepository ($ storage , 'sdtClass ' );
3323
34- public function testeGetTableNameWithValidDataShouldWork ()
35- {
36- $ this ->repository ->setTableName ('ola ' );
37- $ this ->assertEquals ('ola ' , $ this ->repository ->getTableName ());
38- }
24+ $ repository ->setStorage ($ storage , 'sdtClass ' );
3925
40- public function testSetAndGetEntityWithValidDataShouldWork ()
41- {
42- $ this ->repository ->setEntity ($ this ->entity );
4326 $ this ->assertInstanceOf (
44- '\WilliamEspindola\Field\Entity\EntityInterface ' ,
45- $ this ->repository ->getEntity ()
46- );
47- }
48-
49- public function testSetAndGetStorageWithValidDataShouldWork ()
50- {
51- $ this ->repository ->setStorage ($ this ->storage );
52- $ this ->assertInstanceOf (
53- '\WilliamEspindola\Field\Storage\ORM\StorageORMInterface ' ,
54- $ this ->repository ->getStorage ()
27+ 'sdtClass ' ,
28+ $ repository ->getStorage ()
5529 );
5630 }
5731
5832 public function testFindAllShouldReturnAnArrayObject ()
5933 {
60- $ this ->assertInstanceOf ('ArrayObject ' , $ this ->repository ->findAll ());
34+ $ storageAbstract = $ this ->getMock ('sdtClass ' , ['findAll ' ]);
35+
36+ $ storageAbstract ->expects ($ this ->any ())
37+ ->method ('findAll ' )
38+ ->will ($ this ->returnValue ((object )([])));
39+
40+ $ storage = $ this ->getMock ('\WilliamEspindola\Field\Storage\ORM\StorageORMInterface ' );
41+
42+ $ storage ->expects ($ this ->any ())
43+ ->method ('__get ' )
44+ ->with ($ this ->equalTo ('storage ' ))
45+ ->will ($ this ->returnValue ($ storageAbstract ));
46+
47+ $ storage ->expects ($ this ->any ())
48+ ->method ('getRepository ' )
49+ ->will ($ this ->returnValue ($ storageAbstract ));
50+
51+ $ repository = new MockRepository ($ storage , 'sdtClass ' );
52+
53+ $ repository ->setStorage ($ storage , 'sdtClass ' );
54+
55+ $ this ->assertInstanceOf ('stdClass ' , $ repository ->findAll ());
6156 }
6257}
6358
64- class MockRepository extends RepositoryAbstract {}
59+ class MockRepository extends RepositoryAbstract {}
60+
0 commit comments