idSession->loadIfExists( 'PersistentTestObject', 1 ); $this->assertEquals( 'PersistentTestObject', get_class( $first ) ); $second = $this->idSession->loadIfExists( 'PersistentTestObject', 1 ); $this->assertEquals( 'PersistentTestObject', get_class( $first ) ); // Test identity $this->assertSame( $first, $second, 'Object identity different on second load.' ); } public function testLoadIfExistsValidRefetch() { $this->idSession->options->refetch = true; $first = $this->idSession->loadIfExists( 'PersistentTestObject', 1 ); $this->assertEquals( 'PersistentTestObject', get_class( $first ) ); $second = $this->idSession->loadIfExists( 'PersistentTestObject', 1 ); $this->assertEquals( 'PersistentTestObject', get_class( $first ) ); // Test identity $this->assertNotSame( $first, $second, 'Object identity idenitical on second load with refetch.' ); } public function testLoadIfExistsInvalid() { $object = $this->idSession->loadIfExists( 'NoSuchClass', 1 ); $this->assertEquals( null, $object ); } public function testLoadIfExistsNoSuchObject() { $object = $this->idSession->loadIfExists( 'PersistentTestObject', 999 ); $this->assertEquals( null, $object ); } // load public function testLoadValid() { $first = $this->idSession->load( 'PersistentTestObject', "1" ); $this->assertEquals( 'PersistentTestObject', get_class( $first ) ); $second = $this->idSession->load( 'PersistentTestObject', "1" ); $this->assertEquals( 'PersistentTestObject', get_class( $second ) ); // Test identity $this->assertSame( $first, $second, 'Object identity different on second load.' ); } public function testLoadValidRefetch() { $this->idSession->options->refetch = true; $first = $this->idSession->load( 'PersistentTestObject', "1" ); $this->assertEquals( 'PersistentTestObject', get_class( $first ) ); $second = $this->idSession->load( 'PersistentTestObject', "1" ); $this->assertEquals( 'PersistentTestObject', get_class( $second ) ); // Test identity $this->assertNotSame( $first, $second, 'Object identity idenitical on second load with refetch.' ); } public function testLoadInvalid() { try { $object = $this->idSession->load( 'NoSuchClass', 1 ); $this->fail( "load() called with invalid class. Did not get an exception" ); } catch ( ezcPersistentDefinitionNotFoundException $e ) {} } public function testLoadInvalidRefetch() { $this->idSession->options->refetch = true; try { $object = $this->idSession->load( 'NoSuchClass', 1 ); $this->fail( "load() called with invalid class. Did not get an exception" ); } catch ( ezcPersistentDefinitionNotFoundException $e ) {} } public function testLoadNoSuchObject() { try { $object = $this->idSession->load( 'PersistentTestObject', 999 ); $this->fail( "load() called with invalid object id. Did not get an exception" ); } catch ( ezcPersistentQueryException $e ) { $this->assertEquals( "A query failed internally in Persistent Object: No object of class 'PersistentTestObject' with id '999'.", $e->getMessage() ); return; } } public function testLoadNoSuchObjectRefetch() { $this->idSession->options->refetch = true; try { $object = $this->idSession->load( 'PersistentTestObject', 999 ); $this->fail( "load() called with invalid object id. Did not get an exception" ); } catch ( ezcPersistentQueryException $e ) { $this->assertEquals( "A query failed internally in Persistent Object: No object of class 'PersistentTestObject' with id '999'.", $e->getMessage() ); return; } } // loadIntoObject public function testLoadIntoObjectOnceSuccess() { $object = new PersistentTestObject(); $this->idSession->loadIntoObject( $object, 1 ); $this->assertEquals( 'Sweden', $object->varchar ); $this->assertEquals( 9006405, (int)$object->integer ); $this->assertEquals( 449.96, (float)$object->decimal ); $this->assertEquals( 'Sweden has nice girls!', $object->text ); } public function testLoadIntoObjectTwiceFailure() { $first = new PersistentTestObject(); $this->idSession->loadIntoObject( $first, 1 ); $this->assertEquals( 'Sweden', $first->varchar ); $this->assertEquals( 9006405, (int)$first->integer ); $this->assertEquals( 449.96, (float)$first->decimal ); $this->assertEquals( 'Sweden has nice girls!', $first->text ); $second = new PersistentTestObject(); try { $this->idSession->loadIntoObject( $second, 1 ); $this->fail( 'Exception not thrown on load into object of existing instance.' ); } catch ( ezcPersistentIdentityAlreadyExistsException $e ) {} } public function testLoadIntoObjectTwiceSuccessRefetch() { $this->idSession->options->refetch = true; $first = new PersistentTestObject(); $this->idSession->loadIntoObject( $first, 1 ); $this->assertEquals( 'Sweden', $first->varchar ); $this->assertEquals( 9006405, (int)$first->integer ); $this->assertEquals( 449.96, (float)$first->decimal ); $this->assertEquals( 'Sweden has nice girls!', $first->text ); $second = new PersistentTestObject(); $this->idSession->loadIntoObject( $second, 1 ); $this->assertNotSame( $first, $second ); $this->assertEquals( $first, $second ); } public function testLoadIntoObjectInvalid() { try { $object = $this->idSession->loadIntoObject( new Exception(), 1 ); $this->fail( "loadIntoObject() called with invalid class. Did not get an exception" ); } catch ( ezcPersistentDefinitionNotFoundException $e ) { return; } } public function testLoadIntoObjectInvalidRefetch() { $this->idSession->options->refetch = true; try { $object = $this->idSession->loadIntoObject( new Exception(), 1 ); $this->fail( "loadIntoObject() called with invalid class. Did not get an exception" ); } catch ( ezcPersistentDefinitionNotFoundException $e ) { return; } } public function testLoadIntoObjectNoSuchObject() { try { $object = $this->idSession->loadIntoObject( new PersistentTestObject(), 999 ); $this->fail( "loadIntoObject() called with invalid class. Did not get an exception" ); } catch ( ezcPersistentQueryException $e ) { $this->assertEquals( "A query failed internally in Persistent Object: No object of class 'PersistentTestObject' with id '999'.", $e->getMessage() ); } } public function testLoadIntoObjectNoSuchObjectRefetch() { $this->idSession->options->refetch = true; try { $object = $this->idSession->loadIntoObject( new PersistentTestObject(), 999 ); $this->fail( "loadIntoObject() called with invalid class. Did not get an exception" ); } catch ( ezcPersistentQueryException $e ) { $this->assertEquals( "A query failed internally in Persistent Object: No object of class 'PersistentTestObject' with id '999'.", $e->getMessage() ); } } // refresh public function testRefreshValid() { $first = $this->idSession->load( 'PersistentTestObject', 1 ); $second = $this->idSession->load( 'PersistentTestObject', 1 ); $this->assertSame( $first, $second ); $first->integer = 23; $this->assertEquals( 23, $second->integer ); $this->idSession->refresh( $first ); $this->assertSame( $first, $second ); $this->assertEquals( 9006405, (int)$first->integer ); $this->assertEquals( 9006405, (int)$second->integer ); } public function testRefreshInvalid() { try { $this->idSession->refresh( new Exception() ); } catch ( ezcPersistentDefinitionNotFoundException $e ) { return; } $this->fail( "refresh of non-persistent object did not throw exception" ); } public function testRefreshNotPersistent() { try { $this->idSession->refresh( new PersistentTestObject() ); } catch ( ezcPersistentObjectNotPersistentException $e ) { return; } $this->fail( "refresh of non-persistent object did not throw exception" ); } } ?>