public function testHandlePassesToAggregate() { $command = $this->makeCommand(); $this->subject->shouldReceive('getSequence')->withNoArgs()->once()->andReturn(30); $this->subject->shouldReceive('handle')->with($command)->once(); expect_not(RepositoryStub::handle($command)); }
public function testLoginCorrect() { $this->_model = new LoginForm(['email' => '*****@*****.**', 'password' => '123123']); expect_that($this->_model->login()); expect_not(Yii::$app->user->isGuest); expect($this->_model->errors)->hasntKey('password'); }
public function testNotSendEmailsToInactiveUser() { $user = $this->tester->grabFixture('user', 1); $model = new PasswordResetRequestForm(); $model->email = $user['email']; expect_not($model->sendEmail()); }
public function testIsSuperUser() { $authItem = new AuthItem(); expect_not($authItem->isSuperUser()); $authItem->name = User::ROLE_SUPERUSER; expect_that($authItem->isSuperUser()); }
public function testLoginCorrect() { $this->model = new LoginForm(['username' => 'demo', 'password' => 'demo']); expect_that($this->model->login()); expect_not(\Yii::$app->user->isGuest); expect($this->model->errors)->hasntKey('password'); }
/** * @depends testFindUserByUsername */ public function testValidateUser($user) { $user = User::findByUsername('admin'); expect_that($user->validateAuthKey('test100key')); expect_not($user->validateAuthKey('test102key')); expect_that($user->validatePassword('admin')); expect_not($user->validatePassword('123456')); }
public function testNotCorrectSignup() { $model = new SignupForm(['username' => 'troy.becker', 'email' => '*****@*****.**', 'password' => 'some_password']); expect_not($model->signup()); expect_that($model->getErrors('username')); expect_that($model->getErrors('email')); expect($model->getFirstError('username'))->equals('This username has already been taken.'); expect($model->getFirstError('email'))->equals('This email address has already been taken.'); }
/** * @depends testFindUserByUsername */ public function testValidateUser() { /** @var User $user */ $user = User::find()->where(['username' => 'neo'])->one(); expect_that($user->validateAuthKey('neo')); expect_not($user->validateAuthKey('test102key')); //expect_that($user->validatePassword('neo')); //expect_not($user->validatePassword('123456')); }
public function testRegister() { $this->provider->shouldReceive('mergeConfigFrom')->with(Mockery::type('string'), 'ray_emitter')->once(); App::shouldReceive('singleton')->with('rayemitter.store', Mockery::on(function ($closure) { $result = $closure(); expect_that($result); expect($result instanceof Store)->true(); return true; }))->once(); expect_not($this->provider->register()); }
public function testSuccess() { $user = User::findByEmail('*****@*****.**'); expect_not($user->isConfirmed()); $form = new ConfirmEmailForm(); expect_that($form->validateToken($user->email_confirm_token)); expect_that($form->confirmEmail()); $user = User::findByEmail($user->email); expect($user->email_confirm_token)->isEmpty(); expect_that($user->isConfirmed()); }
public function testPublishQueue() { $store = Mockery::mock(EventStore::class)->makePartial(); $payload = [Mockery::mock('stdClass')]; $event_name = 'testEvent'; $event = ['event' => $event_name, 'payload' => $payload]; EventBus::shouldReceive('fire')->with('publish:' . $event_name, $payload)->once(); $this->setPropertyValue($store, 'queue', [$event]); expect_not($store->publishQueue()); $queue = $this->getPropertyValue($store, 'queue'); expect($queue)->equals([]); }
public function testCheckFakePermission() { $config = Yii::getAlias('@app/tests/_data/rbac/permissions.php'); $auth = Yii::$app->authManager; $permission = $auth->createPermission('test'); $auth->add($permission); expect_that($auth->getPermission('test')); $command = new RbacController('test', 'test'); $command->path = $config; $command->beforeAction('test'); $command->actionUp(); expect_not($auth->getPermission('test')); }
/** * @expectedException Exception */ public function testHandleRollsBack() { $subject = new Middleware(); $parameter = 'request'; $callback = function ($request) use($parameter) { expect($request)->equals($parameter); throw new \Exception(); }; DB::shouldReceive('beginTransaction')->withNoArgs()->once(); EventStore::shouldReceive('saveQueue')->withNoArgs()->never(); DB::shouldReceive('rollBack')->withNoArgs()->once(); DB::shouldReceive('commit')->withNoArgs()->never(); expect_not($subject->handle($parameter, $callback)); }
public function testValidationIsSkipped() { $model = new Item05(); $model->status = 'Item05Workflow/new'; expect_that($model->save()); expect_not($model->hasErrors()); $this->specify('model validation is skipped if save is done with no validation', function () use($model) { $model->name = null; $model->status = 'Item05Workflow/correction'; verify('save is successful when no validation is done', $model->save(false))->true(); verify('the model has no errors', $model->hasErrors())->false(); verify('the model status has changed', $model->getWorkflowStatus()->getId())->equals('Item05Workflow/correction'); verify('the status attribute has changed', $model->status)->equals('Item05Workflow/correction'); }); }
public function testSuccess() { $form = new SignupForm(['fullName' => 'Test', 'email' => '*****@*****.**', 'password' => 'test_password']); $user = $form->signup(); expect($user)->isInstanceOf('app\\models\\User'); expect_not($user->isConfirmed()); expect($user->email)->equals('*****@*****.**'); expect_that($user->validatePassword('test_password')); expect_that($form->sendEmail()); $user = User::findByEmail('*****@*****.**'); expect($user->profile->full_name)->equals('Test'); $message = $this->tester->grabLastSentEmail(); expect('valid email is sent', $message)->isInstanceOf('yii\\mail\\MessageInterface'); expect($message->getTo())->hasKey($user->email); expect($message->getFrom())->hasKey('*****@*****.**'); }
public function testStatusEqualsFails() { $item = new Item04(); $item->sendToStatus('A'); expect_not($item->statusEquals('B')); expect_not($item->statusEquals('Item04Workflow/B')); expect_not($item->statusEquals('NOTFOUND')); expect_not($item->statusEquals('Item04Workflow/NOTFOUND')); expect_not($item->statusEquals('NOTFOUND/NOTFOUND')); expect_not($item->statusEquals('invalid name')); expect_not($item->statusEquals('')); expect_not($item->statusEquals(null)); $statusA = $item->getWorkflowStatus(); $item->sendToStatus('B'); verify($item->statusEquals('B')); expect_not($item->statusEquals($statusA)); }
public function testLeaveWorkflowOnDelete() { $post = new Item06(); $post->name = 'post name'; $post->enterWorkflow(); verify($post->save())->true(); verify($post->getWorkflowStatus()->getId())->equals('Item06Workflow/new'); Item06Behavior::$countLeaveWorkflow = 0; $post->canLeaveWorkflow(true); expect_that($post->delete()); verify(Item06Behavior::$countLeaveWorkflow)->equals(1); $post = new Item06(); $post->name = 'post name'; $post->enterWorkflow(); verify($post->save())->true(); verify($post->getWorkflowStatus()->getId())->equals('Item06Workflow/new'); $post->canLeaveWorkflow(false); // refuse leave workflow // Now, the handler attached to the beforeLeaveWorkflow Event (see Item06Behavior) // will invalidate the event and return false (preventing the DELETE operation) expect_not($post->delete()); }
public function testBootClosure() { $tag = ['test-123']; $node = Mockery::mock('C4tech\\Support\\Contracts\\ModelInterface'); $node->parent = Mockery::mock('C4tech\\Support\\Contracts\\ModelInterface[touch]'); $node->parent->shouldReceive('touch')->withNoArgs()->once(); $model = Mockery::mock('stdClass'); $model->shouldReceive('moved')->with(Mockery::on(function ($method) use($node) { expect_not($method($node)); return true; }))->once(); $model->shouldReceive('saved')->with(Mockery::on(function ($method) use($node) { expect_not($method($node)); return true; }))->once(); $model->shouldReceive('deleted')->once(); Config::shouldReceive('get')->with(null, null)->twice()->andReturn($model, null); Config::shouldReceive('get')->with('app.debug')->times(3)->andReturn(true); Log::shouldReceive('info')->with(Mockery::type('string'), Mockery::type('array'))->once(); Log::shouldReceive('debug')->with(Mockery::type('string'), Mockery::type('array'))->twice(); Cache::shouldReceive('tags->flush')->with($tag)->withNoArgs()->once(); $this->repo->shouldReceive('make->getParentTags')->with($node)->withNoArgs()->andReturn($tag); expect_not($this->repo->boot()); }
public function testEmptyToken() { $form = new ResetPasswordForm(); expect_not($form->validateToken('')); }
public function testHydrateLoops() { $event = Mockery::mock('C4tech\\RayEmitter\\Contracts\\Domain\\Event'); $collection = Mockery::mock('C4tech\\RayEmitter\\Contracts\\Event\\Collection[each]'); $collection->shouldReceive('each')->with(Mockery::on(function ($callback) use($event) { $callback($event); return true; }))->once(); $subject = Mockery::mock('C4tech\\Test\\RayEmitter\\Domain\\AggregateStub[apply]')->shouldAllowMockingProtectedMethods(); $subject->shouldReceive('apply')->with($event)->once(); $original_sequence = $subject->getSequence(); expect_not($subject->hydrate($collection)); expect($subject->getSequence())->greaterThan($original_sequence); }
public function testExpectFunctions() { expect(12)->equals(12); expect_that(true); expect_not(false); }
public function testFindUserByUsername() { expect_that($user = User::find()->where(['username' => 'neozzz'])->one()); expect_not(User::find()->where(['username' => 'neo'])->one()); }
public function testUserDeleted() { $form = new PasswordResetRequestForm(); $form->email = '*****@*****.**'; expect_not($form->validate()); }
public function testRelationship() { $relation = 'test'; $method = $this->getMethod('verifyRelationship'); $this->trait->shouldReceive('verifyRelationshipFive')->with(1, $relation, 2, 3, 4, 5, 6, null)->once()->andReturn(true); $this->trait->shouldReceive('verifyRelationshipFour')->with(1, $relation, 2, 3, 4, 5, null)->once()->andReturn(true); $this->trait->shouldReceive('verifyRelationshipThree')->with(1, $relation, 2, 3, 4, null)->once()->andReturn(true); $this->trait->shouldReceive('verifyRelationshipTwo')->with(1, $relation, 2, 3, null)->once()->andReturn(true); $this->trait->shouldReceive('verifyRelationshipOne')->with(1, $relation, 2, null)->once()->andReturn(true); $this->trait->shouldReceive('verifyRelationshipZero')->with(1, $relation, null)->once()->andReturn(true); $args = [1, 2, 3, 4, 5, 6, 7]; $success = false; try { expect_not($method->invoke($this->trait, $relation, $args)); } catch (AssertionException $error) { $success = true; } expect('Throws error on more than 6 args', $success)->true(); array_pop($args); do { expect_not($method->invoke($this->trait, $relation, $args)); array_pop($args); } while (count($args)); $success = false; try { expect_not($method->invoke($this->trait, $relation, $args)); } catch (AssertionException $error) { $success = true; } expect('Throws error on fewer than 1 arg', $success)->true(); }
/** * @expectedException C4tech\RayEmitter\Exceptions\UnknownProperty */ public function testGetterThrowsError() { expect_not($this->subject->other_field); }
public function testRegister() { $this->provider->shouldReceive('mergeConfigFrom')->with(Mockery::type('string'), 'c4tech')->once(); expect_not($this->provider->register()); }
public function testSuccess() { $form = new LoginForm(['email' => '*****@*****.**', 'password' => '123123']); expect_that($form->login()); expect($form->errors)->isEmpty(); expect_not(Yii::$app->user->isGuest); }
public function testSuccess() { $form = new LoginForm(['username' => 'superuser', 'password' => 'fghfgh']); expect_that($form->login()); expect($form->errors)->isEmpty(); expect_not(Yii::$app->user->isGuest); }
public function testListenToUploadModelClosure() { $model = Mockery::mock('UploadableModel'); $repository = Mockery::mock('C4tech\\Upload\\Contracts\\UploadInterface'); $repository->id = 16; $tags = ['tags']; $upload = Mockery::mock('UploadInstance'); $uploadable = Mockery::mock('C4tech\\Upload\\Contracts\\UploadableModelInterface'); $this->repo->shouldReceive('getModelClass')->withNoArgs()->once()->andReturn($model); Config::shouldReceive('get')->with('app.debug')->twice()->andReturn(true); Log::shouldReceive('debug')->with(Mockery::type('string'), Mockery::type('array'))->twice(); $model->shouldReceive('updated'); $model->shouldReceive('deleted'); Upload::shouldReceive('getModelClass')->withNoArgs()->once()->andReturn($upload); $upload->shouldReceive('updated'); $upload->shouldReceive('deleted')->with(Mockery::on(function ($closure) use($upload) { expect_not($closure($upload)); return true; })); Upload::shouldReceive('make')->with($upload)->once()->andReturn($repository); $repository->shouldReceive('getTags')->with($model)->once()->andReturn($tags); Cache::shouldReceive('tags->flush')->with($tags)->withNoArgs()->once(); $this->repo->shouldReceive('withUpload')->with($repository)->once()->andreturn([$uploadable]); $uploadable->shouldReceive('getModel->touch')->withNoArgs()->once(); expect_not($this->repo->listenToUpload()); }
public function testPushCache() { $key = 'test-key-145'; $id = 145; $this->repo->shouldReceive('formatTag')->with($id)->once()->andReturn($key); $object = new stdClass(); $object->exists = true; $object->id = $id; $reflection = new ReflectionClass($this->repo); $method = $reflection->getMethod('pushCache'); $method->setAccessible(true); $object_property = $reflection->getProperty('object'); $object_property->setAccessible(true); $object_property->setValue($this->repo, $object); $instances_property = $reflection->getProperty('instances'); $instances_property->setAccessible(true); $instances = $instances_property->getValue(); expect($instances)->hasntKey($key); expect_not($method->invoke($this->repo)); $instances = $instances_property->getValue(); expect($instances)->hasKey($key); expect($instances[$key])->equals($this->repo); }