Ejemplo n.º 1
0
 /**
  * Testing the clear method for unsetting the attributes of an object.
  *
  * @since 1.0
  * @dataProvider getActiveRecordProviders
  */
 public function testClear($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     $state = $this->person->get('state');
     $this->assertTrue(!empty($state), 'Testing the clear method for unsetting the attributes of an object');
     $reflection = new \ReflectionClass(get_class($this->person));
     $properties = $reflection->getProperties();
     foreach ($properties as $propObj) {
         $propName = $propObj->name;
         if (!in_array($propName, $this->person->getDefaultAttributes()) && !in_array($propName, $this->person->getTransientAttributes())) {
             $this->assertNotNull($this->person->get($propName), 'Testing the clear method for unsetting the attributes of an object');
         }
     }
     // delete will invoke clear(), which is private
     $this->person->delete();
     try {
         $state = $this->person->get('state');
         $this->fail('Testing the clear method for unsetting the attributes of an object');
     } catch (AlphaException $e) {
         $reflection = new \ReflectionClass(get_class($this->person));
         $properties = $reflection->getProperties();
         foreach ($properties as $propObj) {
             $propName = $propObj->name;
             try {
                 $this->person->get($propName);
             } catch (PHPException $e) {
                 $this->assertEquals(preg_match('/Undefined property/', $e->getMessage()), 1, 'Testing the clear method for unsetting the attributes of an object');
             } catch (AlphaException $e) {
                 $this->assertEquals('Could not access the property [' . $propName . '] on the object of class [Alpha\\Model\\Person]', $e->getMessage(), 'Testing the clear method for unsetting the attributes of an object');
             }
         }
     }
 }