/** * Test get. */ public function testGet() { parent::testGet(); $this->given($repository = $this->randomRepository())->and($unique = $this->uniqueValue())->and($friend = new User(UserId::next(), 'Ivan', 32))->and($friend1 = new User(UserId::next(), 'Karel', 32))->and($repository->persist($friend))->and($repository->persist($friend1))->and($unique->addFriend($friend))->and($unique->addFriend($friend1))->and($repository->persist($unique))->when($object = $repository->get($unique->id()))->then()->object($object->fullName())->isEqualTo(StringLiteral::fromNative('Methuselah'))->integer($object->languagesLevel()->get('english'))->isEqualTo(10)->boolean($object->mainRole()->is(Role::ROLE_ADMIN))->isTrue()->array($object->roles()->toArray())->contains(Role::ROLE_ADMIN)->array($object->phonenumbers()->toArray())->contains('+34 685 165 267')->string($object->fax()->number())->isEqualTo('+34-208-1234567')->array($object->addresses()->toArray())->object[0]->isInstanceOf(Address::class)->string($object->addresses()->toArray()[0]->name())->isEqualTo('Home')->object($object->addresses()->toArray()[0]->coordinate())->isEqualTo(Coordinate::fromLatLng(41.390205, 2.154007))->integer($object->friends()->count())->isEqualTo(2); }
/** * Test remove. */ public function testRemove() { $this->given($repository = $this->randomRepository())->and($unique = $this->uniqueValue())->when($repository->persist($unique))->then()->object($repository->get($unique->id()))->isEqualTo($unique)->and()->when($repository->remove($unique))->then()->variable($repository->get($unique->id()))->isNull(); $this->given($repository = $this->randomRepository())->given($id = UserId::next())->then()->exception(function () use($repository, $id) { $repository->remove($id); })->isInstanceOf(\InvalidArgumentException::class); }
/** * Test visitEqual. */ public function testVisitEqual() { $this->visitTest(Criteria::property('foo')->eq(10), function () { return $this->createQueryBuilder()->field('foo')->equals(10); }); $this->visitTest(Criteria::property('foo')->count()->eq(10), function () { return $this->createQueryBuilder()->field('foo')->size(10); }); $user = new User(UserId::next(), 'user', 20); $this->visitTest(Criteria::eq($user), function () use($user) { return $this->createQueryBuilder()->field('id')->equals($user->id()->toNative()); }); $this->visitTest(Criteria::property('id')->eq($user->id()), function () use($user) { return $this->createQueryBuilder()->field('id')->equals($user->id()->toNative()); }); $this->logicExceptionTest(Criteria::callback(function () { })->eq(10)); $this->logicExceptionTest(Criteria::property('foo')->eq(Criteria::property('bar'))); }