예제 #1
0
 public function testTest()
 {
     $user = Model\User::find(1);
     $this->assertEquals(array('firstName' => 'tester'), $user->profile);
     $user->profile = array('firstName' => 'new', 'lastName' => 'user');
     Model\User::save($user);
     $contents = Model\User::getRepo()->getContents();
     $this->assertEquals('{"firstName":"new","lastName":"user"}', $contents[1]['profile']);
 }
예제 #2
0
 public function testTest()
 {
     $user = Model\User::find(1);
     $this->assertEmpty($user->getUnmapped());
     $user->unmappedField = 'some value';
     $user->otherProp = 'val2';
     $this->assertEquals('some value', $user->unmappedField);
     $expected = ['unmappedField' => 'some value', 'otherProp' => 'val2'];
     $this->assertEquals($expected, $user->getUnmapped());
 }
예제 #3
0
파일: SaveTest.php 프로젝트: harp-orm/core
 public function testTest()
 {
     $user1 = Model\User::find(1);
     $user1->name = 'changed name';
     $user1->delete();
     $this->assertNotNull($user1->deletedAt);
     $user2 = new Model\User(['name' => 'new name', 'password' => 'test']);
     $user2->setAddress(new Model\Address(['location' => 'here']))->getPosts()->add(new Model\BlogPost(['name' => 'post name', 'body' => 'some body', 'url' => 'http://example.com/postnew']))->add(new Model\Post(['name' => 'news', 'body' => 'some other body']));
     $address = new Model\Address(['name' => 'new name', 'location' => 'new location']);
     $user3 = new Model\User(['name' => 'new name', 'password' => 'test']);
     Model\User::saveArray([$user1, $user2]);
     Model\Address::save($address);
     $expectedAddressContent = [1 => ['id' => 1, 'name' => null, 'location' => 'test location'], 2 => ['id' => 2, 'name' => null, 'location' => 'here'], 3 => ['id' => 3, 'name' => 'new name', 'location' => 'new location']];
     $this->assertEquals($expectedAddressContent, Model\Address::getRepo()->getContents());
     $expectedPostContent = [1 => ['id' => 1, 'name' => 'post 1', 'body' => 'my post 1', 'userId' => 1, 'class' => 'Harp\\Core\\Test\\Model\\Post'], 2 => ['id' => 2, 'name' => 'post 2', 'body' => 'my post 2', 'userId' => 1, 'url' => 'http://example.com/post2', 'class' => 'Harp\\Core\\Test\\Model\\BlogPost'], 3 => ['id' => 3, 'name' => 'post name', 'body' => 'some body', 'userId' => 3, 'url' => 'http://example.com/postnew', 'class' => 'Harp\\Core\\Test\\Model\\BlogPost'], 4 => ['id' => 4, 'name' => 'news', 'body' => 'some other body', 'userId' => 3, 'class' => 'Harp\\Core\\Test\\Model\\Post']];
     $this->assertEquals($expectedPostContent, Model\Post::getRepo()->getContents());
     $contents = Model\User::getRepo()->getContents();
     $this->assertArrayConstrained(['id' => $this->equalTo(1), 'name' => $this->equalTo('changed name'), 'password' => $this->equalTo(null), 'addressId' => $this->equalTo(1), 'deletedAt' => $this->equalTo($user1->deletedAt), 'isBlocked' => $this->equalTo(true), 'profile' => $this->equalTo('{"firstName":"tester"}')], $contents[1]);
     $this->assertArrayConstrained(['id' => $this->equalTo(2), 'name' => $this->equalTo('deleted'), 'password' => $this->equalTo(null), 'addressId' => $this->equalTo(1), 'deletedAt' => $this->equalTo(1401949982), 'isBlocked' => $this->equalTo(false), 'profile' => $this->equalTo(null)], $contents[2]);
     $this->assertArrayConstrained(['id' => $this->equalTo(3), 'name' => $this->equalTo('new name'), 'password' => $this->equalTo('test'), 'addressId' => $this->equalTo(2), 'deletedAt' => $this->equalTo(null), 'isBlocked' => $this->equalTo(false), 'profile' => $this->equalTo(null)], $contents[3]);
 }
예제 #4
0
 public function testRels()
 {
     $user = Model\User::find(1231421);
     $this->assertInstanceOf('Harp\\Core\\Test\\Model\\User', $user);
     $this->assertTrue($user->isVoid());
     $address = $user->getAddress();
     $this->assertInstanceOf('Harp\\Core\\Test\\Model\\Address', $address);
     $this->assertTrue($address->isVoid());
     $post = $user->getPosts()->getFirst();
     $this->assertInstanceOf('Harp\\Core\\Test\\Model\\Post', $post);
     $this->assertTrue($post->isVoid());
     $user = $post->getUser();
     $this->assertInstanceOf('Harp\\Core\\Test\\Model\\User', $user);
     $this->assertTrue($user->isVoid());
 }
예제 #5
0
 public function testTest()
 {
     $user1 = Model\User::find(1);
     $address1 = $user1->getAddress();
     $post1 = $user1->getPosts()->getFirst();
     $user2 = Model\User::find(1);
     $address2 = $user2->getAddress();
     $post2 = $user2->getPosts()->getFirst();
     $address3 = Model\Address::find(1);
     $post3 = Model\Post::find(1);
     $this->assertSame($user1, $user2);
     $this->assertSame($address1, $address2);
     $this->assertSame($post1, $post2);
     $this->assertSame($address1, $address3);
     $this->assertSame($post1, $post3);
 }
예제 #6
0
 public function testTest()
 {
     $user = Model\User::find(1);
     $name = $user->name;
     $this->assertFalse($user->isChanged());
     $this->assertEmpty($user->getChanges());
     $user->name = 'changed';
     $user->isBlocked = false;
     $this->assertTrue($user->isChanged());
     $this->assertTrue($user->hasChange('name'));
     $this->assertTrue($user->hasChange('isBlocked'));
     $this->assertEquals($name, $user->getOriginal('name'));
     $this->assertEquals(true, $user->getOriginal('isBlocked'));
     $this->assertEquals(['name' => 'changed', 'isBlocked' => false], $user->getChanges());
     $user->name = $name;
     $this->assertTrue($user->isChanged());
     $this->assertFalse($user->hasChange('name'));
     $this->assertTrue($user->hasChange('isBlocked'));
     $this->assertEquals(['isBlocked' => false], $user->getChanges());
     $user->isBlocked = true;
     $this->assertFalse($user->isChanged());
     $this->assertEmpty($user->getChanges());
 }
예제 #7
0
 public function testTest()
 {
     $user1 = Model\User::find(1);
     $posts = $user1->getPosts();
     $this->assertInstanceOf('Harp\\Core\\Test\\Model\\LinkManyPosts', $posts);
 }
예제 #8
0
 public function testTest()
 {
     $users = Model\User::findAll()->loadWith(['posts']);
 }
예제 #9
0
파일: Address.php 프로젝트: harp-orm/core
 public static function initialize(AbstractRepo $repo)
 {
     $repo->setFile('Address.json')->addRels([new Rel\One('user', $repo, User::getRepo())]);
 }
예제 #10
0
파일: Post.php 프로젝트: harp-orm/core
 public static function initialize(AbstractRepo $repo)
 {
     InheritedTrait::initialize($repo);
     $repo->setFile('Post.json')->addRels([new Rel\One('user', $repo, User::getRepo())]);
 }
예제 #11
0
 /**
  * @covers ::getLink
  */
 public function testGetLink()
 {
     $user = User::find(1);
     $link = $user->getLink('address');
     $this->assertSame($user, $link->getModel());
     $this->assertSame(Address::getRepo(), $link->getRel()->getForeignRepo());
 }