Example #1
0
 public function testDataNulls()
 {
     $data = ['title' => 'A Post', 'body' => 'A Body', 'status' => 0, 'author_id' => 1];
     $post = new \SpotTest\Entity\Post($data);
     $post->status = null;
     $this->assertTrue($post->isModified('status'));
     $post->status = 1;
     $this->assertTrue($post->isModified('status'));
     $post->data(['status' => null]);
     $this->assertTrue($post->isModified('status'));
     $post->title = '';
     $this->assertTrue($post->isModified('title'));
     $this->title = null;
     $this->assertTrue($post->isModified('title'));
     $this->title = 'A Post';
     $post->data(['title' => null]);
     $this->assertTrue($post->isModified('title'));
 }
Example #2
0
 public function testAfterSaveEvent()
 {
     $mapper = test_spot_mapper('SpotTest\\Entity\\Post');
     $eventEmitter = $mapper->eventEmitter();
     $post = new \SpotTest\Entity\Post(['title' => 'A title', 'body' => '<p>body</p>', 'status' => 1, 'author_id' => 1, 'date_created' => new \DateTime()]);
     $eventEmitter->removeAllListeners('afterSave');
     \SpotTest\Entity\Post::$events = ['afterSave' => ['mock_save_hook']];
     $mapper->loadEvents();
     $result = $mapper->save($post);
     $this->assertEquals(2, $post->status);
     $eventEmitter->removeAllListeners('afterSave');
 }
Example #3
0
 public function testRelationsAreNotReturnedWithData()
 {
     $post = new \SpotTest\Entity\Post(['title' => 'A Post', 'body' => 'A Body', 'status' => 0, 'data' => ['posts' => 'are cool', 'another field' => 'to serialize'], 'date_created' => new \DateTime()]);
     $author = new \SpotTest\Entity\Author(['email' => '*****@*****.**', 'password' => 'password']);
     $post->author = $author;
     $data = $post->data();
     $this->assertFalse(isset($data['author']));
     $array = $post->toArray();
     $this->assertFalse(isset($array['author']));
 }