Changeset 1303
- Timestamp:
- 01/27/08 17:31:16 (8 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/rdbms/persistence/eraser/stubDatabaseEraser.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseSelect.php (modified) (1 diff)
- trunk/src/test/AllTests.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/rdbms/RDBMSTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/rdbms/persistence/creator/stubDatabaseCreatorTestCase.php (modified) (7 diffs)
- trunk/src/test/php/net/stubbles/rdbms/persistence/eraser/stubDatabaseEraserTestCase.php (modified) (8 diffs)
- trunk/src/test/php/net/stubbles/rdbms/persistence/finder/stubDatabaseFinderTestCase.php (modified) (8 diffs)
- trunk/src/test/php/net/stubbles/rdbms/persistence/serializer/stubDatabaseSerializerTestCase.php (modified) (13 diffs)
- trunk/src/test/php/net/stubbles/rdbms/persistence/stubSetterMethodHelperTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseMySQLQueryBuilderTestCase.php (modified) (15 diffs)
- trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseQueryBuilderFactoryTestCase.php (modified) (8 diffs)
- trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseSelectTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableColumnTestCase.php (modified) (9 diffs)
- trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableDescriptionTestCase.php (modified) (10 diffs)
- trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableJoinTestCase.php (modified) (4 diffs)
- trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableRowTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/service/ServiceTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/service/jsonrpc/stubJsonRpcProcessorTestCase.php (modified) (10 diffs)
- trunk/src/test/php/net/stubbles/service/jsonrpc/stubJsonRpcResponseTestCase.php (modified) (6 diffs)
- trunk/src/test/php/net/stubbles/service/jsonrpc/util/stubJsonRpcProxyGeneratorTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/service/soap/native/stubNativeSoapClientTestCase.php (modified) (6 diffs)
- trunk/src/test/php/net/stubbles/service/soap/stubSoapClientConfigurationTestCase.php (modified) (4 diffs)
- trunk/src/test/run.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/rdbms/persistence/eraser/stubDatabaseEraser.php
r1281 r1303 92 92 $entityClass = (($entity instanceof stubObject) ? ($entity->getClass()) : (new stubReflectionObject($entity))); 93 93 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.'); 95 95 } 96 96 … … 112 112 113 113 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.'); 115 115 } 116 116 … … 119 119 $result->free(); 120 120 } 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); 122 122 } 123 123 } trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseSelect.php
r1301 r1303 7 7 * @subpackage rdbms_querybuilder 8 8 */ 9 stubClassLoader::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 ); 9 14 /** 10 15 * Container for the data of a select query. trunk/src/test/AllTests.php
r1298 r1303 31 31 require_once $dir . '/php/net/stubbles/rdbms/RDBMSTestSuite.php'; 32 32 require_once $dir . '/php/net/stubbles/util/UtilTestSuite.php'; 33 require_once $dir . '/php/net/stubbles/service/ServiceTestSuite.php'; 33 34 require_once $dir . '/php/net/stubbles/websites/WebsitesTestSuite.php'; 34 35 require_once $dir . '/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php'; … … 65 66 $suite->addTestSuite('RDBMSTestSuite'); 66 67 $suite->addTestSuite('UtilTestSuite'); 68 $suite->addTestSuite('ServiceTestSuite'); 67 69 $suite->addTestSuite('WebsitesTestSuite'); 68 70 $suite->addTestSuite('VariantManagerTestSuite'); trunk/src/test/php/net/stubbles/rdbms/RDBMSTestSuite.php
r1298 r1303 45 45 46 46 // 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'); 52 52 53 53 // 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'); 61 61 return $suite; 62 62 } trunk/src/test/php/net/stubbles/rdbms/persistence/creator/stubDatabaseCreatorTestCase.php
r1225 r1303 8 8 */ 9 9 stubClassLoader::load('net::stubbles::rdbms::persistence::creator::stubDatabaseCreator'); 10 Mock::generate('stubDatabaseConnection');11 10 require_once dirname(__FILE__) . '/../../querybuilder/TeststubDatabaseQueryBuilder.php'; 12 11 require_once dirname(__FILE__) . '/../MockNoEntityAnnotationEntity.php'; … … 19 18 * @subpackage rdbms_persistence_creator_test 20 19 */ 21 class stubDatabaseCreatorTestCase extends UnitTestCase20 class stubDatabaseCreatorTestCase extends PHPUnit_Framework_TestCase 22 21 { 23 22 /** … … 30 29 * mock for pdo 31 30 * 32 * @var SimpleMock31 * @var PHPUnit_Framework_MockObject_MockObject 33 32 */ 34 33 protected $mockConnection; … … 45 44 public function setUp() 46 45 { 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')); 50 49 $this->mockQueryBuilder = new TeststubDatabaseQueryBuilder(); 51 50 stubDatabaseQueryBuilderFactory::setInstantiatedQueryBuilder('mock', $this->mockQueryBuilder); … … 63 62 /** 64 63 * test the hash code 64 * 65 * @test 65 66 */ 66 public function testHashCode()67 public function hashCode() 67 68 { 68 $this->assertEqual ($this->dbCreator->hashCode(), 'creator:mock');69 $this->assertEquals('creator:mock', $this->dbCreator->hashCode()); 69 70 } 70 71 71 72 /** 72 73 * check that database creator instances are the same for the same connection 74 * 75 * @test 73 76 */ 74 public function testInstancesAreTheSameForSameConnection()77 public function instancesAreTheSameForSameConnection() 75 78 { 76 79 $dbCreator = stubDatabaseCreator::getInstance($this->mockConnection); 77 $this->assert Reference($this->dbCreator, $dbCreator);80 $this->assertSame($this->dbCreator, $dbCreator); 78 81 } 79 82 80 83 /** 81 84 * check that database creator instances differant for the same connection if it should be refreshed 85 * 86 * @test 82 87 */ 83 public function testInstancesAreDifferentForSameConnectionOnRefresh()88 public function instancesAreDifferentForSameConnectionOnRefresh() 84 89 { 85 90 $dbCreator = stubDatabaseCreator::getInstance($this->mockConnection, true); 86 $this->assert True($this->dbCreator !==$dbCreator);91 $this->assertNotSame($this->dbCreator, $dbCreator); 87 92 } 88 93 89 94 /** 90 95 * check that database creator instances are differant for for differant connections 96 * 97 * @test 91 98 */ 92 public function testInstancesAreDifferantForDifferantConnections()99 public function instancesAreDifferantForDifferantConnections() 93 100 { 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')); 96 103 $dbCreator = stubDatabaseCreator::getInstance($mockConnection); 97 $this-> assertNotIdentical($this->dbCreator, $dbCreator);104 $this->logicalNot(($this->identicalTo($this->dbCreator, $dbCreator))); 98 105 } 99 106 100 107 /** 101 108 * check that a class that is missing the DBTable annotation throws an exception 109 * 110 * @test 111 * @expectedException stubPersistenceException 102 112 */ 103 public function testClassWithoutEntityAnnotation()113 public function classWithoutEntityAnnotation() 104 114 { 105 $this->expectException('stubPersistenceException');106 115 $this->dbCreator->createTable(new stubReflectionClass('MockNoEntityAnnotationEntity')); 107 116 } … … 109 118 /** 110 119 * check that a class that is missing the DBTable annotation throws an exception 120 * 121 * @test 111 122 */ 112 public function testClassWithoutDBTableAnnotation()123 public function classWithoutDBTableAnnotation() 113 124 { 114 125 $this->dbCreator->createTable(new stubReflectionClass('MockNoTableAnnotationEntity')); 115 126 $tableDescription = $this->mockQueryBuilder->getTableDescription(); 116 $this->assertEqual ($tableDescription->getName(), 'MockNoTableAnnotationEntitys');127 $this->assertEquals($tableDescription->getName(), 'MockNoTableAnnotationEntitys'); 117 128 $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()); 122 133 $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()); 126 137 $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()); 130 141 $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()); 134 145 $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()); 138 149 $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()); 142 153 $this->assertFalse($columns[6]->isPrimaryKey()); 143 154 } … … 145 156 /** 146 157 * check that a class that is missing the DBTable annotation throws an exception 158 * 159 * @test 147 160 */ 148 public function testClassWithDBTableAnnotation()161 public function classWithDBTableAnnotation() 149 162 { 150 163 $this->dbCreator->createTable(new stubReflectionClass('MockSinglePrimaryKeyEntity')); 151 164 $tableDescription = $this->mockQueryBuilder->getTableDescription(); 152 $this->assertEqual ($tableDescription->getName(), 'foo');165 $this->assertEquals($tableDescription->getName(), 'foo'); 153 166 $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()); 156 169 $this->assertTrue($columns[1]->isPrimaryKey()); 157 $this->assertEqual ($columns[2]->getName(), 'bar');170 $this->assertEquals('bar', $columns[2]->getName()); 158 171 $this->assertFalse($columns[2]->isPrimaryKey()); 159 $this->assertEqual ($columns[3]->getName(), 'default');172 $this->assertEquals('default', $columns[3]->getName()); 160 173 $this->assertFalse($columns[3]->isPrimaryKey()); 161 174 } trunk/src/test/php/net/stubbles/rdbms/persistence/eraser/stubDatabaseEraserTestCase.php
r1225 r1303 8 8 */ 9 9 stubClassLoader::load('net::stubbles::rdbms::persistence::eraser::stubDatabaseEraser'); 10 Mock::generate('stubDatabaseConnection');11 Mock::generate('stubDatabaseResult');12 Mock::generate('stubCriterion');13 10 require_once dirname(__FILE__) . '/../../querybuilder/TeststubDatabaseQueryBuilder.php'; 14 11 require_once dirname(__FILE__) . '/../MockNoEntityAnnotationEntity.php'; … … 32 29 * @subpackage rdbms_persistence_erasertest 33 30 */ 34 class stubDatabaseEraserTestCase extends UnitTestCase31 class stubDatabaseEraserTestCase extends PHPUnit_Framework_TestCase 35 32 { 36 33 /** … … 43 40 * mock for pdo 44 41 * 45 * @var SimpleMock42 * @var PHPUnit_Framework_MockObject_MockObject 46 43 */ 47 44 protected $mockConnection; … … 58 55 public function setUp() 59 56 { 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')); 63 60 $this->mockQueryBuilder = new TeststubDatabaseQueryBuilder(); 64 61 stubDatabaseQueryBuilderFactory::setInstantiatedQueryBuilder('mock', $this->mockQueryBuilder); … … 76 73 /** 77 74 * 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()); 82 81 } 83 82 84 83 /** 85 84 * 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() 88 89 { 89 90 $dbEraser = stubDatabaseEraser::getInstance($this->mockConnection); 90 $this->assert Reference($this->dbEraser, $dbEraser);91 $this->assertSame($this->dbEraser, $dbEraser); 91 92 } 92 93 93 94 /** 94 95 * 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() 97 100 { 98 101 $dbEraser = stubDatabaseEraser::getInstance($this->mockConnection, true); 99 $this->assert True($this->dbEraser !==$dbEraser);102 $this->assertNotSame($this->dbEraser, $dbEraser); 100 103 } 101 104 102 105 /** 103 106 * 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')); 109 114 $dbEraser = stubDatabaseEraser::getInstance($mockConnection); 110 $this-> assertNotIdentical($this->dbEraser, $dbEraser);115 $this->logicalNot(($this->identicalTo($this->dbEraser, $dbEraser))); 111 116 } 112 117 113 118 /** 114 119 * 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 { 119 126 $this->dbEraser->deleteByPrimaryKeys('foo'); 120 127 } … … 122 129 /** 123 130 * 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 { 128 137 $this->dbEraser->deleteByPrimaryKeys(new MockNoEntityAnnotationEntity()); 129 138 } … … 131 140 /** 132 141 * 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 { 137 148 $this->dbEraser->deleteByPrimaryKeys(new MockNoPrimaryKeyEntity()); 138 149 } … … 140 151 /** 141 152 * test that deleting data of an object with its primary keys 142 */ 143 public function testByPrimaryKeys() 153 * 154 * @test 155 */ 156 public function byPrimaryKeys() 144 157 { 145 158 $entity = new MockNoTableAnnotationEntity(); 146 159 $entity->setId('mock'); 147 $this->mockConnection-> setReturnValue('query', new MockstubDatabaseResult());160 $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($this->getMock('stubDatabaseResult'))); 148 161 $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()); 151 164 } 152 165 153 166 /** 154 167 * test that deleting data of an object with its primary keys 155 */ 156 public function testByPrimaryKeysWithDBTableAnnotation() 168 * 169 * @test 170 */ 171 public function byPrimaryKeysWithDBTableAnnotation() 157 172 { 158 173 $entity = new MockSinglePrimaryKeyEntity(); 159 174 $entity->setId('mock'); 160 $this->mockConnection-> setReturnValue('query', new MockstubDatabaseResult());175 $this->mockConnection->expects($this->any())->method('query')->will($this->returnValue($this->getMock('stubDatabaseResult'))); 161 176 $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()); 164 179 } 165 180 166 181 /** 167 182 * 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)); 177 193 $data = $this->dbEraser->deleteByCriterion($mockCriterion, new stubReflectionClass('MockNoTableAnnotationEntity')); 178 $this->assertEqual ($data, 0);194 $this->assertEquals(0, $data); 179 195 $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()); 183 199 } 184 200 185 201 /** 186 202 * 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)); 196 213 $data = $this->dbEraser->deleteByCriterion($mockCriterion, new stubReflectionClass('MockSinglePrimaryKeyEntity')); 197 $this->assertEqual ($data, 0);214 $this->assertEquals(0, $data); 198 215 $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()); 202 219 } 203 220 204 221 /** 205 222 * 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')); 211 230 } 212 231 } trunk/src/test/php/net/stubbles/rdbms/persistence/finder/stubDatabaseFinderTestCase.php
r1225 r1303 8 8 */ 9 9 stubClassLoader::load('net::stubbles::rdbms::persistence::finder::stubDatabaseFinder'); 10 Mock::generate('stubDatabaseConnection');11 Mock::generate('stubDatabaseResult');12 Mock::generate('stubCriterion');13 10 require_once dirname(__FILE__) . '/../../querybuilder/TeststubDatabaseQueryBuilder.php'; 14 11 require_once dirname(__FILE__) . '/../MockNoTableAnnotationEntity.php'; … … 60 57 * @subpackage rdbms_persistence_finder_test 61 58 */ 62 class stubDatabaseFinderTestCase extends UnitTestCase59 class stubDatabaseFinderTestCase extends PHPUnit_Framework_TestCase 63 60 { 64 61 /** … … 71 68 * mock for pdo 72 69 * 73 * @var SimpleMock70 * @var PHPUnit_Framework_MockObject_MockObject 74 71 */ 75 72 protected $mockConnection; … … 86 83 public function setUp() 87 84 { 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')); 91 88 $this->mockQueryBuilder = new TeststubDatabaseQueryBuilder(); 92 89 stubDatabaseQueryBuilderFactory::setInstantiatedQueryBuilder('mock', $this->mockQueryBuilder); … … 104 101 /** 105 102 * 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()); 110 109 } 111 110 112 111 /** 113 112 * 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() 116 117 { 117 118 $dbFinder = stubDatabaseFinder::getInstance($this->mockConnection); 118 $this->assert Reference($this->dbFinder, $dbFinder);119 $this->assertSame($this->dbFinder, $dbFinder); 119 120 } 120 121 121 122 /** 122 123 * 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() 125 128 { 126 129 $dbFinder = stubDatabaseFinder::getInstance($this->mockConnection, true); 127 $this->assert True($this->dbFinder !==$dbFinder);130 $this->assertNotSame($this->dbFinder, $dbFinder); 128 131 } 129 132 130 133 /** 131 134 * 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')); 137 142 $dbFinder = stubDatabaseFinder::getInstance($mockConnection); 138 $this-> assertNotIdentical($this->dbFinder, $dbFinder);143 $this->logicalNot(($this->identicalTo($this->dbFinder, $dbFinder))); 139 144 } 140 145 141 146 /** 142 147 * 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 { 147 154 $this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockNoEntityAnnotationEntity'), array()); 148 155 } … … 150 157 /** 151 158 * 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.'))); 159 169 $this->assertNull($this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockSinglePrimaryKeyEntity'), array('id' => 'mock'))); 160 170 $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()); 166 175 } 167 176 168 177 /** 169 178 * 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.'))); 177 189 $this->assertNull($this->dbFinder->findByPrimaryKeys(new stubReflectionClass('MockNoTableAnnotationEntity'), array('id' => 'mock'))); 178 190 $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()); 182 251 $select = $this->mockQueryBuilder->getSelect(); 183 $this->assertEqual($select->getBaseTableName(), 'MockNoTableAnnotationEntitys'); 252 $this->assertEquals('foo', $select->getBaseTableName()); 253 $this->assertTrue($select->hasCriterion()); 184 254 } 185 255 186 256 /** 187 257 * 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
