Changeset 1303

Show
Ignore:
Timestamp:
01/27/08 17:31:16 (8 months ago)
Author:
mikey
Message:

continued refactoring #118: converted tests for net::stubbles::rdbms and net::stubbles::service

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/rdbms/persistence/eraser/stubDatabaseEraser.php

    r1281 r1303  
    9292        $entityClass = (($entity instanceof stubObject) ? ($entity->getClass()) : (new stubReflectionObject($entity))); 
    9393        if ($entityClass->hasAnnotation('Entity') === false) { 
    94             throw new stubPersistenceException('Class ' . $entity->getClassName() . ' is not an entity.'); 
     94            throw new stubPersistenceException('Class ' . $entityClass->getFullQualifiedClassName() . ' is not an entity.'); 
    9595        } 
    9696         
     
    112112         
    113113        if ($criterion->hasCriterion() === false) { 
    114             throw new stubDatabaseEraserException('Can not delete instance of ' . $entity->getClassName() . ' by its primary keys as it has no primary key.'); 
     114            throw new stubDatabaseEraserException('Can not delete instance of ' . $entityClass->getFullQualifiedClassName() . ' by its primary keys as it has no primary key.'); 
    115115        } 
    116116         
     
    119119            $result->free(); 
    120120        } catch (stubException $se) { 
    121             throw new stubDatabaseEraserException('Can not delete instance of ' . $entity->getClassName() . ' by its primary keys.', $se); 
     121            throw new stubDatabaseEraserException('Can not delete instance of ' . $entityClass->getFullQualifiedClassName() . ' by its primary keys.', $se); 
    122122        } 
    123123    } 
  • trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseSelect.php

    r1301 r1303  
    77 * @subpackage  rdbms_querybuilder 
    88 */ 
     9stubClassLoader::load('net::stubbles::util::validators::stubAndCriterion', 
     10                      'net::stubbles::util::validators::stubCriterion', 
     11                      'net::stubbles::rdbms::querybuilder::stubDatabaseTableDescription', 
     12                      'net::stubbles::rdbms::querybuilder::stubDatabaseTableJoin' 
     13); 
    914/** 
    1015 * Container for the data of a select query. 
  • trunk/src/test/AllTests.php

    r1298 r1303  
    3131require_once $dir . '/php/net/stubbles/rdbms/RDBMSTestSuite.php'; 
    3232require_once $dir . '/php/net/stubbles/util/UtilTestSuite.php'; 
     33require_once $dir . '/php/net/stubbles/service/ServiceTestSuite.php'; 
    3334require_once $dir . '/php/net/stubbles/websites/WebsitesTestSuite.php'; 
    3435require_once $dir . '/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php'; 
     
    6566        $suite->addTestSuite('RDBMSTestSuite'); 
    6667        $suite->addTestSuite('UtilTestSuite'); 
     68        $suite->addTestSuite('ServiceTestSuite'); 
    6769        $suite->addTestSuite('WebsitesTestSuite'); 
    6870        $suite->addTestSuite('VariantManagerTestSuite'); 
  • trunk/src/test/php/net/stubbles/rdbms/RDBMSTestSuite.php

    r1298 r1303  
    4545         
    4646        // persistence 
    47         #$suite->addTestFile($dir . '/persistence/stubSetterMethodHelperTestCase.php'); 
    48         #$suite->addTestFile($dir . '/persistence/creator/stubDatabaseCreatorTestCase.php'); 
    49         #$suite->addTestFile($dir . '/persistence/eraser/stubDatabaseEraserTestCase.php'); 
    50         #$suite->addTestFile($dir . '/persistence/finder/stubDatabaseFinderTestCase.php'); 
    51         #$suite->addTestFile($dir . '/persistence/serializer/stubDatabaseSerializerTestCase.php'); 
     47        $suite->addTestFile($dir . '/persistence/stubSetterMethodHelperTestCase.php'); 
     48        $suite->addTestFile($dir . '/persistence/creator/stubDatabaseCreatorTestCase.php'); 
     49        $suite->addTestFile($dir . '/persistence/eraser/stubDatabaseEraserTestCase.php'); 
     50        $suite->addTestFile($dir . '/persistence/finder/stubDatabaseFinderTestCase.php'); 
     51        $suite->addTestFile($dir . '/persistence/serializer/stubDatabaseSerializerTestCase.php'); 
    5252         
    5353        // querybuilder 
    54         #$suite->addTestFile($dir . '/querybuilder/stubDatabaseMySQLQueryBuilderTestCase.php'); 
    55         #$suite->addTestFile($dir . '/querybuilder/stubDatabaseQueryBuilderFactoryTestCase.php'); 
    56         #$suite->addTestFile($dir . '/querybuilder/stubDatabaseSelectTestCase.php'); 
    57         #$suite->addTestFile($dir . '/querybuilder/stubDatabaseTableColumnTestCase.php'); 
    58         #$suite->addTestFile($dir . '/querybuilder/stubDatabaseTableDescriptionTestCase.php'); 
    59         #$suite->addTestFile($dir . '/querybuilder/stubDatabaseTableJoinTestCase.php'); 
    60         #$suite->addTestFile($dir . '/querybuilder/stubDatabaseTableRowTestCase.php'); 
     54        $suite->addTestFile($dir . '/querybuilder/stubDatabaseMySQLQueryBuilderTestCase.php'); 
     55        $suite->addTestFile($dir . '/querybuilder/stubDatabaseQueryBuilderFactoryTestCase.php'); 
     56        $suite->addTestFile($dir . '/querybuilder/stubDatabaseSelectTestCase.php'); 
     57        $suite->addTestFile($dir . '/querybuilder/stubDatabaseTableColumnTestCase.php'); 
     58        $suite->addTestFile($dir . '/querybuilder/stubDatabaseTableDescriptionTestCase.php'); 
     59        $suite->addTestFile($dir . '/querybuilder/stubDatabaseTableJoinTestCase.php'); 
     60        $suite->addTestFile($dir . '/querybuilder/stubDatabaseTableRowTestCase.php'); 
    6161        return $suite; 
    6262    } 
  • trunk/src/test/php/net/stubbles/rdbms/persistence/creator/stubDatabaseCreatorTestCase.php

    r1225 r1303  
    88 */ 
    99stubClassLoader::load('net::stubbles::rdbms::persistence::creator::stubDatabaseCreator'); 
    10 Mock::generate('stubDatabaseConnection'); 
    1110require_once dirname(__FILE__) . '/../../querybuilder/TeststubDatabaseQueryBuilder.php'; 
    1211require_once dirname(__FILE__) . '/../MockNoEntityAnnotationEntity.php'; 
     
    1918 * @subpackage  rdbms_persistence_creator_test 
    2019 */ 
    21 class stubDatabaseCreatorTestCase extends UnitTestCase 
     20class stubDatabaseCreatorTestCase extends PHPUnit_Framework_TestCase 
    2221{ 
    2322    /** 
     
    3029     * mock for pdo 
    3130     * 
    32      * @var  SimpleMock 
     31     * @var  PHPUnit_Framework_MockObject_MockObject 
    3332     */ 
    3433    protected $mockConnection; 
     
    4544    public function setUp() 
    4645    { 
    47         $this->mockConnection = new MockstubDatabaseConnection(); 
    48         $this->mockConnection->setReturnValue('hashCode', 'mock'); 
    49         $this->mockConnection->setReturnValue('getDatabase', 'mock'); 
     46        $this->mockConnection = $this->getMock('stubDatabaseConnection'); 
     47        $this->mockConnection->expects($this->any())->method('hashCode')->will($this->returnValue('mock')); 
     48        $this->mockConnection->expects($this->any())->method('getDatabase')->will($this->returnValue('mock')); 
    5049        $this->mockQueryBuilder = new TeststubDatabaseQueryBuilder(); 
    5150        stubDatabaseQueryBuilderFactory::setInstantiatedQueryBuilder('mock', $this->mockQueryBuilder); 
     
    6362    /** 
    6463     * test the hash code 
     64     * 
     65     * @test 
    6566     */ 
    66     public function testHashCode() 
     67    public function hashCode() 
    6768    { 
    68         $this->assertEqual($this->dbCreator->hashCode(), 'creator:mock'); 
     69        $this->assertEquals('creator:mock', $this->dbCreator->hashCode()); 
    6970    } 
    7071 
    7172    /** 
    7273     * check that database creator instances are the same for the same connection 
     74     * 
     75     * @test 
    7376     */ 
    74     public function testInstancesAreTheSameForSameConnection() 
     77    public function instancesAreTheSameForSameConnection() 
    7578    { 
    7679        $dbCreator = stubDatabaseCreator::getInstance($this->mockConnection); 
    77         $this->assertReference($this->dbCreator, $dbCreator); 
     80        $this->assertSame($this->dbCreator, $dbCreator); 
    7881    } 
    7982 
    8083    /** 
    8184     * check that database creator instances differant for the same connection if it should be refreshed 
     85     * 
     86     * @test 
    8287     */ 
    83     public function testInstancesAreDifferentForSameConnectionOnRefresh() 
     88    public function instancesAreDifferentForSameConnectionOnRefresh() 
    8489    { 
    8590        $dbCreator = stubDatabaseCreator::getInstance($this->mockConnection, true); 
    86         $this->assertTrue($this->dbCreator !== $dbCreator); 
     91        $this->assertNotSame($this->dbCreator, $dbCreator); 
    8792    } 
    8893 
    8994    /** 
    9095     * check that database creator instances are differant for for differant connections 
     96     * 
     97     * @test 
    9198     */ 
    92     public function testInstancesAreDifferantForDifferantConnections() 
     99    public function instancesAreDifferantForDifferantConnections() 
    93100    { 
    94         $mockConnection = new MockstubDatabaseConnection(); 
    95         $mockConnection->setReturnValue('hashCode', 'mock2'); 
     101        $mockConnection = $this->getMock('stubDatabaseConnection'); 
     102        $mockConnection->expects($this->any())->method('hashCode')->will($this->returnValue('mock2')); 
    96103        $dbCreator = stubDatabaseCreator::getInstance($mockConnection); 
    97         $this->assertNotIdentical($this->dbCreator, $dbCreator); 
     104        $this->logicalNot(($this->identicalTo($this->dbCreator, $dbCreator))); 
    98105    } 
    99106 
    100107    /** 
    101108     * check that a class that is missing the DBTable annotation throws an exception 
     109     * 
     110     * @test 
     111     * @expectedException  stubPersistenceException 
    102112     */ 
    103     public function testClassWithoutEntityAnnotation() 
     113    public function classWithoutEntityAnnotation() 
    104114    { 
    105         $this->expectException('stubPersistenceException'); 
    106115        $this->dbCreator->createTable(new stubReflectionClass('MockNoEntityAnnotationEntity')); 
    107116    } 
     
    109118    /** 
    110119     * check that a class that is missing the DBTable annotation throws an exception 
     120     * 
     121     * @test 
    111122     */ 
    112     public function testClassWithoutDBTableAnnotation() 
     123    public function classWithoutDBTableAnnotation() 
    113124    { 
    114125        $this->dbCreator->createTable(new stubReflectionClass('MockNoTableAnnotationEntity')); 
    115126        $tableDescription = $this->mockQueryBuilder->getTableDescription(); 
    116         $this->assertEqual($tableDescription->getName(), 'MockNoTableAnnotationEntitys'); 
     127        $this->assertEquals($tableDescription->getName(), 'MockNoTableAnnotationEntitys'); 
    117128        $columns = $tableDescription->getColumns(); 
    118         $this->assertEqual(count($columns), 6); 
    119         $this->assertEqual($columns[1]->getName(), 'id'); 
    120         $this->assertEqual($columns[1]->getType(), 'INT'); 
    121         $this->assertEqual($columns[1]->getSize(), 10); 
     129        $this->assertEquals(6, count($columns)); 
     130        $this->assertEquals('id', $columns[1]->getName()); 
     131        $this->assertEquals('INT', $columns[1]->getType()); 
     132        $this->assertEquals(10, $columns[1]->getSize()); 
    122133        $this->assertTrue($columns[1]->isPrimaryKey()); 
    123         $this->assertEqual($columns[2]->getName(), 'bar'); 
    124         $this->assertEqual($columns[2]->getType(), 'VARCHAR'); 
    125         $this->assertEqual($columns[2]->getSize(), 10); 
     134        $this->assertEquals('bar', $columns[2]->getName()); 
     135        $this->assertEquals('VARCHAR', $columns[2]->getType()); 
     136        $this->assertEquals(10, $columns[2]->getSize()); 
    126137        $this->assertFalse($columns[2]->isPrimaryKey()); 
    127         $this->assertEqual($columns[3]->getName(), 'defaultValue'); 
    128         $this->assertEqual($columns[3]->getType(), 'VARCHAR'); 
    129         $this->assertEqual($columns[3]->getSize(), 255); 
     138        $this->assertEquals('defaultValue', $columns[3]->getName()); 
     139        $this->assertEquals('VARCHAR', $columns[3]->getType()); 
     140        $this->assertEquals(255, $columns[3]->getSize()); 
    130141        $this->assertFalse($columns[3]->isPrimaryKey()); 
    131         $this->assertEqual($columns[4]->getName(), 'intValue'); 
    132         $this->assertEqual($columns[4]->getType(), 'INT'); 
    133         $this->assertEqual($columns[4]->getSize(), 10); 
     142        $this->assertEquals('intValue', $columns[4]->getName()); 
     143        $this->assertEquals('INT', $columns[4]->getType()); 
     144        $this->assertEquals(10, $columns[4]->getSize()); 
    134145        $this->assertFalse($columns[4]->isPrimaryKey()); 
    135         $this->assertEqual($columns[5]->getName(), 'boolValue'); 
    136         $this->assertEqual($columns[5]->getType(), 'TINYINT'); 
    137         $this->assertEqual($columns[5]->getSize(), 1); 
     146        $this->assertEquals('boolValue', $columns[5]->getName()); 
     147        $this->assertEquals('TINYINT', $columns[5]->getType()); 
     148        $this->assertEquals(1, $columns[5]->getSize()); 
    138149        $this->assertFalse($columns[5]->isPrimaryKey()); 
    139         $this->assertEqual($columns[6]->getName(), 'floatValue'); 
    140         $this->assertEqual($columns[6]->getType(), 'FLOAT'); 
    141         $this->assertEqual($columns[6]->getSize(), 10); 
     150        $this->assertEquals('floatValue', $columns[6]->getName()); 
     151        $this->assertEquals('FLOAT', $columns[6]->getType()); 
     152        $this->assertEquals(10, $columns[6]->getSize()); 
    142153        $this->assertFalse($columns[6]->isPrimaryKey()); 
    143154    } 
     
    145156    /** 
    146157     * check that a class that is missing the DBTable annotation throws an exception 
     158     * 
     159     * @test 
    147160     */ 
    148     public function testClassWithDBTableAnnotation() 
     161    public function classWithDBTableAnnotation() 
    149162    { 
    150163        $this->dbCreator->createTable(new stubReflectionClass('MockSinglePrimaryKeyEntity')); 
    151164        $tableDescription = $this->mockQueryBuilder->getTableDescription(); 
    152         $this->assertEqual($tableDescription->getName(), 'foo'); 
     165        $this->assertEquals($tableDescription->getName(), 'foo'); 
    153166        $columns = $tableDescription->getColumns(); 
    154         $this->assertEqual(count($columns), 3); 
    155         $this->assertEqual($columns[1]->getName(), 'id'); 
     167        $this->assertEquals(3, count($columns)); 
     168        $this->assertEquals('id', $columns[1]->getName()); 
    156169        $this->assertTrue($columns[1]->isPrimaryKey()); 
    157         $this->assertEqual($columns[2]->getName(), 'bar'); 
     170        $this->assertEquals('bar', $columns[2]->getName()); 
    158171        $this->assertFalse($columns[2]->isPrimaryKey()); 
    159         $this->assertEqual($columns[3]->getName(), 'default'); 
     172        $this->assertEquals('default', $columns[3]->getName()); 
    160173        $this->assertFalse($columns[3]->isPrimaryKey()); 
    161174    } 
  • trunk/src/test/php/net/stubbles/rdbms/persistence/eraser/stubDatabaseEraserTestCase.php

    r1225 r1303  
    88 */ 
    99stubClassLoader::load('net::stubbles::rdbms::persistence::eraser::stubDatabaseEraser'); 
    10 Mock::generate('stubDatabaseConnection'); 
    11 Mock::generate('stubDatabaseResult'); 
    12 Mock::generate('stubCriterion'); 
    1310require_once dirname(__FILE__) . '/../../querybuilder/TeststubDatabaseQueryBuilder.php'; 
    1411require_once dirname(__FILE__) . '/../MockNoEntityAnnotationEntity.php'; 
     
    3229 * @subpackage  rdbms_persistence_erasertest 
    3330 */ 
    34 class stubDatabaseEraserTestCase extends UnitTestCase 
     31class stubDatabaseEraserTestCase extends PHPUnit_Framework_TestCase 
    3532{ 
    3633    /** 
     
    4340     * mock for pdo 
    4441     * 
    45      * @var  SimpleMock 
     42     * @var  PHPUnit_Framework_MockObject_MockObject 
    4643     */ 
    4744    protected $mockConnection; 
     
    5855    public function setUp() 
    5956    { 
    60         $this->mockConnection = new MockstubDatabaseConnection(); 
    61         $this->mockConnection->setReturnValue('hashCode', 'mock'); 
    62         $this->mockConnection->setReturnValue('getDatabase', 'mock'); 
     57        $this->mockConnection = $this->getMock('stubDatabaseConnection'); 
     58        $this->mockConnection->expects($this->any())->method('hashCode')->will($this->returnValue('mock')); 
     59        $this->mockConnection->expects($this->any())->method('getDatabase')->will($this->returnValue('mock')); 
    6360        $this->mockQueryBuilder = new TeststubDatabaseQueryBuilder(); 
    6461        stubDatabaseQueryBuilderFactory::setInstantiatedQueryBuilder('mock', $this->mockQueryBuilder); 
     
    7673    /** 
    7774     * test the hash code 
    78      */ 
    79     public function testHashCode() 
    80     { 
    81         $this->assertEqual($this->dbEraser->hashCode(), 'eraser:mock'); 
     75     * 
     76     * @test 
     77     */ 
     78    public function hashCode() 
     79    { 
     80        $this->assertEquals('eraser:mock', $this->dbEraser->hashCode()); 
    8281    } 
    8382 
    8483    /** 
    8584     * check that database eraser instances are the same for the same connection 
    86      */ 
    87     public function testInstancesAreTheSameForSameConnection() 
     85     * 
     86     * @test 
     87     */ 
     88    public function instancesAreTheSameForSameConnection() 
    8889    { 
    8990        $dbEraser = stubDatabaseEraser::getInstance($this->mockConnection); 
    90         $this->assertReference($this->dbEraser, $dbEraser); 
     91        $this->assertSame($this->dbEraser, $dbEraser); 
    9192    } 
    9293 
    9394    /** 
    9495     * check that database eraser instances differant for the same connection if it should be refreshed 
    95      */ 
    96     public function testInstancesAreDifferentForSameConnectionOnRefresh() 
     96     * 
     97     * @test 
     98     */ 
     99    public function instancesAreDifferentForSameConnectionOnRefresh() 
    97100    { 
    98101        $dbEraser = stubDatabaseEraser::getInstance($this->mockConnection, true); 
    99         $this->assertTrue($this->dbEraser !== $dbEraser); 
     102        $this->assertNotSame($this->dbEraser, $dbEraser); 
    100103    } 
    101104 
    102105    /** 
    103106     * check that database eraser instances are differant for for differant connections 
    104      */ 
    105     public function testInstancesAreDifferantForDifferantConnections() 
    106     { 
    107         $mockConnection = new MockstubDatabaseConnection(); 
    108         $mockConnection->setReturnValue('hashCode', 'mock2'); 
     107     * 
     108     * @test 
     109     */ 
     110    public function instancesAreDifferantForDifferantConnections() 
     111    { 
     112        $mockConnection = $this->getMock('stubDatabaseConnection'); 
     113        $mockConnection->expects($this->any())->method('hashCode')->will($this->returnValue('mock2')); 
    109114        $dbEraser = stubDatabaseEraser::getInstance($mockConnection); 
    110         $this->assertNotIdentical($this->dbEraser, $dbEraser); 
     115        $this->logicalNot(($this->identicalTo($this->dbEraser, $dbEraser))); 
    111116    } 
    112117 
    113118    /** 
    114119     * check that a cnon-object throws an exception 
    115      */ 
    116     public function testByPrimaryKeysClassWithNonObject() 
    117     { 
    118         $this->expectException('stubIllegalArgumentException'); 
     120     * 
     121     * @test 
     122     * @expectedException  stubIllegalArgumentException 
     123     */ 
     124    public function byPrimaryKeysClassWithNonObject() 
     125    { 
    119126        $this->dbEraser->deleteByPrimaryKeys('foo'); 
    120127    } 
     
    122129    /** 
    123130     * test that trying to delete a class that does not have an entity annotation throws an exception 
    124      */ 
    125     public function testByPrimaryKeysNonEntityClass() 
    126     { 
    127         $this->expectException('stubPersistenceException'); 
     131     * 
     132     * @test 
     133     * @expectedException  stubPersistenceException 
     134     */ 
     135    public function byPrimaryKeysNonEntityClass() 
     136    { 
    128137        $this->dbEraser->deleteByPrimaryKeys(new MockNoEntityAnnotationEntity()); 
    129138    } 
     
    131140    /** 
    132141     * check that a class that is missing any primary keys throws an exception 
    133      */ 
    134     public function testByPrimaryKeysClassWithoutIdAnnotation() 
    135     { 
    136         $this->expectException('stubDatabaseEraserException'); 
     142     * 
     143     * @test 
     144     * @expectedException  stubDatabaseEraserException 
     145     */ 
     146    public function byPrimaryKeysClassWithoutIdAnnotation() 
     147    { 
    137148        $this->dbEraser->deleteByPrimaryKeys(new MockNoPrimaryKeyEntity()); 
    138149    } 
     
    140151    /** 
    141152     * test that deleting data of an object with its primary keys 
    142      */ 
    143     public function testByPrimaryKeys() 
     153     * 
     154     * @test 
     155     */ 
     156    public function byPrimaryKeys() 
    144157    { 
    145158        $entity = new MockNoTableAnnotationEntity(); 
    146159        $entity->setId('mock'); 
    147         $this->mockConnection->setReturnValue('query', new MockstubDatabaseResult()); 
     160        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($this->getMock('stubDatabaseResult'))); 
    148161        $this->dbEraser->deleteByPrimaryKeys($entity); 
    149         $this->assertEqual($this->mockQueryBuilder->getDeleteTable(), 'MockNoTableAnnotationEntitys'); 
    150         $this->assertEqual($this->mockQueryBuilder->getDeleteCriterion()->toSQL(), "(`MockNoTableAnnotationEntitys`.`id` = 'mock')"); 
     162        $this->assertEquals('MockNoTableAnnotationEntitys', $this->mockQueryBuilder->getDeleteTable()); 
     163        $this->assertEquals("(`MockNoTableAnnotationEntitys`.`id` = 'mock')", $this->mockQueryBuilder->getDeleteCriterion()->toSQL()); 
    151164    } 
    152165 
    153166    /** 
    154167     * test that deleting data of an object with its primary keys 
    155      */ 
    156     public function testByPrimaryKeysWithDBTableAnnotation() 
     168     * 
     169     * @test 
     170     */ 
     171    public function byPrimaryKeysWithDBTableAnnotation() 
    157172    { 
    158173        $entity = new MockSinglePrimaryKeyEntity(); 
    159174        $entity->setId('mock'); 
    160         $this->mockConnection->setReturnValue('query', new MockstubDatabaseResult()); 
     175        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($this->getMock('stubDatabaseResult'))); 
    161176        $this->dbEraser->deleteByPrimaryKeys($entity); 
    162         $this->assertEqual($this->mockQueryBuilder->getDeleteTable(), 'foo'); 
    163         $this->assertEqual($this->mockQueryBuilder->getDeleteCriterion()->toSQL(), "(`foo`.`id` = 'mock')"); 
     177        $this->assertEquals('foo', $this->mockQueryBuilder->getDeleteTable()); 
     178        $this->assertEquals("(`foo`.`id` = 'mock')", $this->mockQueryBuilder->getDeleteCriterion()->toSQL()); 
    164179    } 
    165180 
    166181    /** 
    167182     * test that deleting data of an object with a criterion works as expected 
    168      */ 
    169     public function testByCriterion() 
    170     { 
    171         $mockCriterion = new MockstubCriterion(); 
    172         $mockCriterion->setReturnValue('toSQL', 'example'); 
    173         $mockResult = new MockstubDatabaseResult(); 
    174         $this->mockConnection->setReturnValue('query', $mockResult); 
    175         $mockResult->setReturnValueAt(0, 'count', 0); 
    176         $mockResult->setReturnValueAt(1, 'count', 1); 
     183     * 
     184     * @test 
     185     */ 
     186    public function byCriterion() 
     187    { 
     188        $mockCriterion = $this->getMock('stubCriterion'); 
     189        $mockCriterion->expects($this->any())->method('toSQL')->will($this->returnValue('example')); 
     190        $mockResult = $this->getMock('stubDatabaseResult'); 
     191        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($mockResult)); 
     192        $mockResult->expects($this->exactly(2))->method('count')->will($this->onConsecutiveCalls(0, 1)); 
    177193        $data = $this->dbEraser->deleteByCriterion($mockCriterion, new stubReflectionClass('MockNoTableAnnotationEntity')); 
    178         $this->assertEqual($data, 0); 
     194        $this->assertEquals(0, $data); 
    179195        $data = $this->dbEraser->deleteByCriterion($mockCriterion, new stubReflectionClass('MockNoTableAnnotationEntity')); 
    180         $this->assertEqual($data, 1); 
    181         $this->assertEqual($this->mockQueryBuilder->getDeleteTable(), 'MockNoTableAnnotationEntitys'); 
    182         $this->assertEqual($this->mockQueryBuilder->getDeleteCriterion()->toSQL(), "example"); 
     196        $this->assertEquals(1, $data); 
     197        $this->assertEquals('MockNoTableAnnotationEntitys', $this->mockQueryBuilder->getDeleteTable()); 
     198        $this->assertEquals('example', $this->mockQueryBuilder->getDeleteCriterion()->toSQL()); 
    183199    } 
    184200 
    185201    /** 
    186202     * test that deleting data of an object with a criterion works as expected 
    187      */ 
    188     public function testByCriterionWithDBTableAnnotation() 
    189     { 
    190         $mockCriterion = new MockstubCriterion(); 
    191         $mockCriterion->setReturnValue('toSQL', 'example'); 
    192         $mockResult = new MockstubDatabaseResult(); 
    193         $this->mockConnection->setReturnValue('query', $mockResult); 
    194         $mockResult->setReturnValueAt(0, 'count', 0); 
    195         $mockResult->setReturnValueAt(1, 'count', 1); 
     203     * 
     204     * @test 
     205     */ 
     206    public function byCriterionWithDBTableAnnotation() 
     207    { 
     208        $mockCriterion = $this->getMock('stubCriterion'); 
     209        $mockCriterion->expects($this->any())->method('toSQL')->will($this->returnValue('example')); 
     210        $mockResult = $this->getMock('stubDatabaseResult'); 
     211        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($mockResult)); 
     212        $mockResult->expects($this->exactly(2))->method('count')->will($this->onConsecutiveCalls(0, 1)); 
    196213        $data = $this->dbEraser->deleteByCriterion($mockCriterion, new stubReflectionClass('MockSinglePrimaryKeyEntity')); 
    197         $this->assertEqual($data, 0); 
     214        $this->assertEquals(0, $data); 
    198215        $data = $this->dbEraser->deleteByCriterion($mockCriterion, new stubReflectionClass('MockSinglePrimaryKeyEntity')); 
    199         $this->assertEqual($data, 1); 
    200         $this->assertEqual($this->mockQueryBuilder->getDeleteTable(), 'foo'); 
    201         $this->assertEqual($this->mockQueryBuilder->getDeleteCriterion()->toSQL(), "example"); 
     216        $this->assertEquals(1, $data); 
     217        $this->assertEquals('foo', $this->mockQueryBuilder->getDeleteTable()); 
     218        $this->assertEquals('example', $this->mockQueryBuilder->getDeleteCriterion()->toSQL()); 
    202219    } 
    203220 
    204221    /** 
    205222     * test that trying to delete a class that does not have an entity annotation throws an exception 
    206      */ 
    207     public function testByCriterionNonEntityClass() 
    208     { 
    209         $this->expectException('stubPersistenceException'); 
    210         $this->dbEraser->deleteByCriterion(new MockstubCriterion(), new stubReflectionClass('MockNoEntityAnnotationEntity')); 
     223     * 
     224     * @test 
     225     * @expectedException  stubPersistenceException 
     226     */ 
     227    public function byCriterionNonEntityClass() 
     228    { 
     229        $this->dbEraser->deleteByCriterion($this->getMock('stubCriterion'), new stubReflectionClass('MockNoEntityAnnotationEntity')); 
    211230    } 
    212231} 
  • trunk/src/test/php/net/stubbles/rdbms/persistence/finder/stubDatabaseFinderTestCase.php

    r1225 r1303  
    88 */ 
    99stubClassLoader::load('net::stubbles::rdbms::persistence::finder::stubDatabaseFinder'); 
    10 Mock::generate('stubDatabaseConnection'); 
    11 Mock::generate('stubDatabaseResult'); 
    12 Mock::generate('stubCriterion'); 
    1310require_once dirname(__FILE__) . '/../../querybuilder/TeststubDatabaseQueryBuilder.php'; 
    1411require_once dirname(__FILE__) . '/../MockNoTableAnnotationEntity.php'; 
     
    6057 * @subpackage  rdbms_persistence_finder_test 
    6158 */ 
    62 class stubDatabaseFinderTestCase extends UnitTestCase 
     59class stubDatabaseFinderTestCase extends PHPUnit_Framework_TestCase 
    6360{ 
    6461    /** 
     
    7168     * mock for pdo 
    7269     * 
    73      * @var  SimpleMock 
     70     * @var  PHPUnit_Framework_MockObject_MockObject 
    7471     */ 
    7572    protected $mockConnection; 
     
    8683    public function setUp() 
    8784    { 
    88         $this->mockConnection = new MockstubDatabaseConnection(); 
    89         $this->mockConnection->setReturnValue('hashCode', 'mock'); 
    90         $this->mockConnection->setReturnValue('getDatabase', 'mock'); 
     85        $this->mockConnection = $this->getMock('stubDatabaseConnection'); 
     86        $this->mockConnection->expects($this->any())->method('hashCode')->will($this->returnValue('mock')); 
     87        $this->mockConnection->expects($this->any())->method('getDatabase')->will($this->returnValue('mock')); 
    9188        $this->mockQueryBuilder = new TeststubDatabaseQueryBuilder(); 
    9289        stubDatabaseQueryBuilderFactory::setInstantiatedQueryBuilder('mock', $this->mockQueryBuilder); 
     
    104101    /** 
    105102     * test the hash code 
    106      */ 
    107     public function testHashCode() 
    108     { 
    109         $this->assertEqual($this->dbFinder->hashCode(), 'finder:mock'); 
     103     * 
     104     * @test 
     105     */ 
     106    public function hashCode() 
     107    { 
     108        $this->assertEquals('finder:mock', $this->dbFinder->hashCode()); 
    110109    } 
    111110 
    112111    /** 
    113112     * check that database finder instances are the same for the same connection 
    114      */ 
    115     public function testInstancesAreTheSameForSameConnection() 
     113     * 
     114     * @test 
     115     */ 
     116    public function instancesAreTheSameForSameConnection() 
    116117    { 
    117118        $dbFinder = stubDatabaseFinder::getInstance($this->mockConnection); 
    118         $this->assertReference($this->dbFinder, $dbFinder); 
     119        $this->assertSame($this->dbFinder, $dbFinder); 
    119120    } 
    120121 
    121122    /** 
    122123     * check that database finder instances differant for the same connection if it should be refreshed 
    123      */ 
    124     public function testInstancesAreDifferentForSameConnectionOnRefresh() 
     124     * 
     125     * @test 
     126     */ 
     127    public function instancesAreDifferentForSameConnectionOnRefresh() 
    125128    { 
    126129        $dbFinder = stubDatabaseFinder::getInstance($this->mockConnection, true); 
    127         $this->assertTrue($this->dbFinder !== $dbFinder); 
     130        $this->assertNotSame($this->dbFinder, $dbFinder); 
    128131    } 
    129132 
    130133    /** 
    131134     * check that database finder instances are differant for for differant connections 
    132      */ 
    133     public function testInstancesAreDifferantForDifferantConnections() 
    134     { 
    135         $mockConnection = new MockstubDatabaseConnection(); 
    136         $mockConnection->setReturnValue('hashCode', 'mock2'); 
     135     * 
     136     * @test 
     137     */ 
     138    public function instancesAreDifferantForDifferantConnections() 
     139    { 
     140        $mockConnection = $this->getMock('stubDatabaseConnection'); 
     141        $mockConnection->expects($this->any())->method('hashCode')->will($this->returnValue('mock2')); 
    137142        $dbFinder = stubDatabaseFinder::getInstance($mockConnection); 
    138         $this->assertNotIdentical($this->dbFinder, $dbFinder); 
     143        $this->logicalNot(($this->identicalTo($this->dbFinder, $dbFinder))); 
    139144    } 
    140145 
    141146    /** 
    142147     * test that trying to find a class that does not have an entity annotation throws an exception 
    143      */ 
    144     public function testByPrimaryKeysNonEntity() 
    145     { 
    146         $this->expectException('stubPersistenceException'); 
     148     * 
     149     * @test 
     150     * @expectedException  stubPersistenceException 
     151     */ 
     152    public function byPrimaryKeysNonEntity() 
     153    { 
    147154        $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockNoEntityAnnotationEntity'), array()); 
    148155    } 
     
    150157    /** 
    151158     * test that finding data of an object with its primary keys 
    152      */ 
    153     public function testByPrimaryKeys() 
    154     { 
    155         $mockResult = new MockstubDatabaseResult(); 
    156         $this->mockConnection->setReturnValue('query', $mockResult); 
    157         $mockResult->setReturnValueAt(0, 'fetch', false); 
    158         $mockResult->setReturnValueAt(1, 'fetch', array('id' => 'mock', 'bar' => 'Here is bar.', 'default' => 'And this is default.')); 
     159     * 
     160     * @test 
     161     */ 
     162    public function byPrimaryKeys() 
     163    { 
     164        $mockResult = $this->getMock('stubDatabaseResult'); 
     165        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($mockResult)); 
     166        $mockResult->expects($this->exactly(2)) 
     167                   ->method('fetch') 
     168                   ->will($this->onConsecutiveCalls(false, array('id' => 'mock', 'bar' => 'Here is bar.', 'default' => 'And this is default.'))); 
    159169        $this->assertNull($this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockSinglePrimaryKeyEntity'), array('id' => 'mock'))); 
    160170        $singlePrimaryKey = $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockSinglePrimaryKeyEntity'), array('id' => 'mock')); 
    161         $this->assertEqual($singlePrimaryKey->getId(), 'mock'); 
    162         $this->assertEqual($singlePrimaryKey->withAnnotation(), 'Here is bar.'); 
    163         $this->assertEqual($singlePrimaryKey->withDefaultValue(), 'And this is default.'); 
    164         $select = $this->mockQueryBuilder->getSelect(); 
    165         $this->assertEqual($select->getBaseTableName(), 'foo'); 
     171        $this->assertEquals('mock', $singlePrimaryKey->getId()); 
     172        $this->assertEquals('Here is bar.', $singlePrimaryKey->withAnnotation()); 
     173        $this->assertEquals('And this is default.', $singlePrimaryKey->withDefaultValue()); 
     174        $this->assertEquals('foo', $this->mockQueryBuilder->getSelect()->getBaseTableName()); 
    166175    } 
    167176 
    168177    /** 
    169178     * test that finding data of an object with its primary keys 
    170      */ 
    171     public function testByPrimaryKeysWithoutTableAnnotation() 
    172     { 
    173         $mockResult = new MockstubDatabaseResult(); 
    174         $this->mockConnection->setReturnValue('query', $mockResult); 
    175         $mockResult->setReturnValueAt(0, 'fetch', false); 
    176         $mockResult->setReturnValueAt(1, 'fetch', array('id' => 'mock', 'bar' => 'Here is bar.', 'defaultValue' => 'And this is default.')); 
     179     * 
     180     * @test 
     181     */ 
     182    public function byPrimaryKeysWithoutTableAnnotation() 
     183    { 
     184        $mockResult = $this->getMock('stubDatabaseResult'); 
     185        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($mockResult)); 
     186        $mockResult->expects($this->exactly(2)) 
     187                   ->method('fetch') 
     188                   ->will($this->onConsecutiveCalls(false, array('id' => 'mock', 'bar' => 'Here is bar.', 'defaultValue' => 'And this is default.'))); 
    177189        $this->assertNull($this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockNoTableAnnotationEntity'), array('id' => 'mock'))); 
    178190        $entity = $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockNoTableAnnotationEntity'), array('id' => 'mock')); 
    179         $this->assertEqual($entity->getId(), 'mock'); 
    180         $this->assertEqual($entity->withAnnotation(), 'Here is bar.'); 
    181         $this->assertEqual($entity->getDefaultValue(), 'And this is default.'); 
     191        $this->assertEquals('mock', $entity->getId()); 
     192        $this->assertEquals('Here is bar.', $entity->withAnnotation()); 
     193        $this->assertEquals('And this is default.', $entity->getDefaultValue()); 
     194        $this->assertEquals('MockNoTableAnnotationEntitys', $this->mockQueryBuilder->getSelect()->getBaseTableName()); 
     195    } 
     196 
     197    /** 
     198     * test that instance args are transmitted correct 
     199     * 
     200     * @test 
     201     */ 
     202    public function byPrimaryKeysWithInstanceArguments() 
     203    { 
     204        $mockCriterion = $this->getMock('stubCriterion'); 
     205        $mockCriterion->expects($this->any())->method('toSQL')->will($this->returnValue('example')); 
     206        $mockResult = $this->getMock('stubDatabaseResult'); 
     207        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($mockResult)); 
     208        $mockResult->expects($this->exactly(2)) 
     209                   ->method('fetch') 
     210                   ->will($this->returnValue(array('foo' => 'notUsed'))); 
     211        $entity = $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockInstanceArgsEntity'), array(), array('foo', 'bar')); 
     212        $this->assertEquals('foo', $entity->getArg1()); 
     213        $this->assertEquals('bar', $entity->getArg2()); 
     214        $entity = $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockInstanceArgsEntity'), array(), array('foo')); 
     215        $this->assertEquals('foo', $entity->getArg1()); 
     216        $this->assertNull($entity->getArg2()); 
     217    } 
     218 
     219    /** 
     220     * test that trying to find a class that does not have an entity annotation throws an exception 
     221     * 
     222     * @test 
     223     * @expectedException  stubPersistenceException 
     224     */ 
     225    public function byCriterionNonEntity() 
     226    { 
     227        $this->dbFinder->findByCriterion($this->getMock('stubCriterion'), new stubReflectionClass('MockNoEntityAnnotationEntity')); 
     228    } 
     229 
     230    /** 
     231     * test that finding data of an object with a criterion works as expected 
     232     * 
     233     * @test 
     234     */ 
     235    public function byCriterion() 
     236    { 
     237        $mockCriterion = $this->getMock('stubCriterion'); 
     238        $mockCriterion->expects($this->any())->method('toSQL')->will($this->returnValue('example')); 
     239        $mockResult = $this->getMock('stubDatabaseResult'); 
     240        $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($mockResult)); 
     241        $mockResult->expects($this->exactly(2)) 
     242                   ->method('fetchAll') 
     243                   ->will($this->onConsecutiveCalls(false, array(array('bar' => 'Here is bar.', 'default' => 'And this is default.')))); 
     244        $finderResult = $this->dbFinder->findByCriterion($mockCriterion, new stubReflectionClass('MockSinglePrimaryKeyEntity')); 
     245        $this->assertEquals(0, $finderResult->count()); 
     246        $finderResult = $this->dbFinder->findByCriterion($mockCriterion, new stubReflectionClass('MockSinglePrimaryKeyEntity')); 
     247        $this->assertEquals(1, $finderResult->count()); 
     248        $data = $finderResult->current(); 
     249        $this->assertEquals('Here is bar.', $data->withAnnotation()); 
     250        $this->assertEquals('And this is default.', $data->withDefaultValue()); 
    182251        $select = $this->mockQueryBuilder->getSelect(); 
    183         $this->assertEqual($select->getBaseTableName(), 'MockNoTableAnnotationEntitys'); 
     252        $this->assertEquals('foo', $select->getBaseTableName()); 
     253        $this->assertTrue($select->hasCriterion()); 
    184254    } 
    185255 
    186256    /** 
    187257     * test that instance args are transmitted correct 
    188      */ 
    189     public function testByPrimaryKeysWithInstanceArguments() 
    190     { 
    191         $mockCriterion = new MockstubCriterion(); 
    192         $mockCriterion->setReturnValue('toSQL', 'example'); 
    193         $mockResult = new MockstubDatabaseResult(); 
    194         $this->mockConnection->setReturnValue('query', $mockResult); 
    195         $mockResult->setReturnValue('fetch', array('foo' => 'notUsed')); 
    196         $entity = $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockInstanceArgsEntity'), array(), array('foo', 'bar')); 
    197         $this->assertEqual($entity->getArg1(), 'foo'); 
    198         $this->assertEqual($entity->getArg2(), 'bar'); 
    199         $entity = $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockInstanceArgsEntity'), array(), array('foo')); 
    200         $this->assertEqual($entity->getArg1(), 'foo'); 
    201         $this->assertNull($entity->getArg2()); 
    202     } 
    203  
    204     /** 
    205      * test that trying to find a class that does not have an entity annotation throws an exception 
    206      */ 
    207     public function testByCriterionNonEntity() 
    208     { 
    209         $this->expectException('stubPersistenceException'); 
    210         $this->dbFinder->findByCriterion(new MockstubCriterion(), new stubReflectionClass('MockNoEntityAnnotationEntity')); 
    211     } 
    212  
    213     /** 
    214      * test that finding data of an object with a criterion works as expected 
    215      */ 
    216     public function testByCriterion() 
    217     { 
    218         $mockCriterion = new MockstubCriterion(); 
    219         $mockCriterion->setReturnValue('toSQL', 'example'); 
    220         $mockResult = new MockstubDatabaseResult(); 
    221         $this->mockConnection->setReturnValue('query', $mockResult); 
    222         $mockResult->setReturnValueAt(0, 'fetchAll', false); 
    223         $mockResult->setReturnValueAt(1, 'fetchAll', array(array('bar' => 'Here is bar.', 'default' => 'And this is default.'))); 
    224         $finderResult = $this->dbFinder->findByCriterion($mockCriterion, new stubReflectionClass('MockSinglePrimaryKeyEntity')); 
    225         $this->assertEqual($finderResult->count(), 0); 
    226         $finderResult = $this->dbFinder->findByCriterion($mockCriterion, new stubReflectionClass('MockSinglePrimaryKeyEntity')); 
    227         $this->assertEqual($finderResult->count(), 1); 
    228         $data = $finderResult->current(); 
    229&nb