Exemple #1
0
 public function testBuildingWithCustomService()
 {
     /* Given... (Fixture) */
     $params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryType' => 'users']);
     $defaultBuilder = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\AbstractBuilderInterface', ['create' => Stub::never()]);
     $userBuilder = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\BuilderInterface', ['create' => Stub::once()]);
     $builder = new Builder();
     $builder->addBuilder($defaultBuilder, Builder::DEFAULT_BUILDER)->addBuilder($userBuilder, 'users');
     /* When... (Action) */
     $entity = $builder->create($params, [], []);
     /* Then... (Assertions) */
 }
Exemple #2
0
 public function testDeletingWithCustomService()
 {
     /* Given... (Fixture) */
     $params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryType' => 'users']);
     $entity = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\ResourceEntityInterface');
     $defaultDeleter = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\DeleterInterface', ['create' => Stub::never()]);
     $userDeleter = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\DeleterInterface', ['create' => Stub::once()]);
     $deleter = new Deleter();
     $deleter->addDeleter($defaultDeleter, Deleter::DEFAULT_DELETER)->addDeleter($userDeleter, 'users');
     /* When... (Action) */
     $entity = $deleter->delete($params, $entity);
     /* Then... (Assertions) */
 }
Exemple #3
0
 public function testDeletingWithCustomService()
 {
     /* Given... (Fixture) */
     $params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryType' => 'users']);
     $entity = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\ResourceEntityInterface');
     $defaultMutator = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\MutatorInterface', ['create' => Stub::never()]);
     $userMutator = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\MutatorInterface', ['create' => Stub::once()]);
     $mutator = new Mutator();
     $mutator->addMutator($defaultMutator, Mutator::DEFAULT_MUTATOR)->addMutator($userMutator, 'users');
     /* When... (Action) */
     $entity = $mutator->update($params, $entity, [], []);
     /* Then... (Assertions) */
 }
Exemple #4
0
 public static function matcherProvider()
 {
     return array(array(0, Stub::never()), array(1, Stub::once()), array(2, Stub::atLeastOnce()), array(3, Stub::exactly(3)), array(1, Stub::once(function () {
         return true;
     }), true), array(2, Stub::atLeastOnce(function () {
         return array();
     }), array()), array(1, Stub::exactly(1, function () {
         return null;
     }), null), array(1, Stub::exactly(1, function () {
         return 'hello world!';
     }), 'hello world!'));
 }
 public function testSaveUpdate()
 {
     $this->testSaveInsert();
     $stub_record = Stub::makeEmptyExcept('Comment', 'save', ['tableName' => function () {
         return 'comment';
     }, 'beforeSave' => Stub::once(function () {
         return true;
     }), 'beforeInsert' => Stub::never(function () {
         return true;
     }), 'afterInsert' => Stub::never(function () {
         return true;
     }), 'afterSave' => Stub::once(function () {
         return true;
     }), 'beforeUpdate' => Stub::once(function () {
         return true;
     }), 'afterUpdate' => Stub::once(function () {
         return true;
     }), 'getColumns' => function () {
         return ['id', 'username', 'post_id'];
     }]);
     $stub_record->id = 1;
     $stub_record->username = '******';
     $stub_record->post_id = 1;
     $result = $stub_record->save();
     $this->assertSame('testuser2', $stub_record->username);
     $this->assertTrue(is_numeric($stub_record->id));
     $this->assertTrue($result);
 }