public function testFindAll()
 {
     $repository = m::spy(TranslationRepository::class);
     $service = new TranslationService($repository);
     $service->findAll([]);
     $repository->shouldHaveReceived('getByCriteria')->with([])->once();
 }
Example #2
0
 public function testAuthorisedConsumerLanguage()
 {
     $userConsumer = m::spy(ConsumerInterface::class);
     $this->consumerManager->set($userConsumer);
     $this->consumerManager->language();
     $userConsumer->shouldhaveReceived('language');
 }
 public function setUp()
 {
     parent::setUp();
     $this->illuminateDispatcher = m::spy('Illuminate\\Events\\Dispatcher');
     $this->logger = m::spy('Illuminate\\Log\\Writer');
     $this->dispatcher = new EventDispatcher($this->illuminateDispatcher, $this->logger);
 }
 /**
  * @test
  */
 function it_can_accept_arbitrary_query_vars()
 {
     $query = Mockery::spy(WP_User_Query::class);
     $builder = new QueryBuilder($query);
     $builder->set('count_total', false);
     $query->shouldHaveReceived('set')->with('count_total', false);
 }
Example #5
0
 public function testWithCustomFieldName()
 {
     $mockQuery = m::spy('query');
     $filter = KeywordFilter::fromKeywords('keywords', 'title');
     $filter->applyToEloquent($mockQuery);
     $mockQuery->shouldHaveReceived('where')->with('title', 'LIKE', '%keywords%')->once();
 }
Example #6
0
 public function testPluginsAreBooted()
 {
     $this->kernel->shouldReceive('getPlugins')->andReturn([$plugin1 = \Mockery::spy(PluginInterface::class), $plugin2 = \Mockery::spy(PluginInterface::class)]);
     new Application($this->kernel);
     $plugin1->shouldHaveReceived('boot')->once();
     $plugin2->shouldHaveReceived('boot')->once();
 }
 public function init()
 {
     $this->mockManager = m::spy('Eloquence\\Behaviours\\CountCache\\CountCacheManager');
     $this->observer = new CountCacheObserver();
     $this->observer->setManager($this->mockManager);
     $this->model = new RealModelStub();
 }
 public function setUp()
 {
     $this->emitter = \Mockery::spy(Emitter::class);
     $this->event = \Mockery::mock(EventInterface::class);
     $this->message = DomainMessage::recordNow(0, 0, new Metadata(), $this->event);
     $this->eventPublishingListener = new EventPublishingListener($this->emitter);
 }
 public function test_it_can_load_arbitrary_addons()
 {
     $stub = Mockery::spy(Addon::class);
     $repository = $this->app->make(AddonRepository::class);
     $repository->enableAddon($stub);
     $stub->shouldHaveReceived('enable')->once();
 }
Example #10
0
 public function testFilterWithActiveValidAccount()
 {
     $mockRequest = m::spy('requestor');
     CurrentAccount::shouldReceive('determine')->once()->andReturn($this->mockAccount);
     CurrentAccount::shouldReceive('set')->once()->with($this->mockAccount);
     $this->middleware->handle($mockRequest, function () {
     });
 }
Example #11
0
 public function testBuildWithCompilerPass()
 {
     $pass = \Mockery::mock('Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface');
     $builder = \Mockery::spy(new ContainerBuilder());
     $this->plugin->shouldReceive('getCompilerPasses')->andReturn([$pass]);
     $this->plugin->build($builder);
     $builder->shouldHaveReceived('addCompilerPass')->once()->with($pass);
 }
Example #12
0
 public function testAddNamespace()
 {
     $mockFileLoader = m::spy(FileLoader::class);
     $mockRepository = m::spy(TranslationRepositoryInterface::class);
     $translationLoader = new TranslationLoader($mockFileLoader, $mockRepository);
     $translationLoader->addNamespace('shift', 'shift');
     $mockFileLoader->shouldHaveReceived('addNamespace')->once()->with('shift', 'shift');
 }
 public function testSetsUpAssets()
 {
     $shiftAssetContainer = m::spy('assetContainer');
     Asset::shouldReceive('container')->once()->with('shift')->andReturn($shiftAssetContainer);
     $composer = new LayoutsInstallationComposer();
     $composer->compose();
     $shiftAssetContainer->shouldHaveReceived('add')->twice();
 }
Example #14
0
 /**
  * @test
  */
 public function itVerifiesAMethodWasCalledWithSpecificArguments()
 {
     $spy = m::spy();
     $spy->myMethod(123, "a string");
     $spy->shouldHaveReceived("myMethod")->with(123, "a string");
     $spy->shouldHaveReceived("myMethod", array(123, "a string"));
     $this->setExpectedException("Mockery\\Exception\\InvalidCountException");
     $spy->shouldHaveReceived("myMethod")->with(123);
 }
Example #15
0
 public function testEventTriggered()
 {
     $event = \Mockery::mock('Havvg\\Component\\Lifecycle\\Event\\EventInterface');
     $provider = \Mockery::mock('Havvg\\Component\\Lifecycle\\Event\\EventProviderInterface');
     $processor = \Mockery::spy('Havvg\\Component\\Lifecycle\\Event\\EventProcessorInterface');
     $lifecycle = new Lifecycle($provider, $processor);
     $lifecycle->onEventTriggered(new EventTriggeredEvent($event));
     $processor->shouldHaveReceived('process')->once()->with($event);
 }
 /**
  * @depends testAddConsequence
  * @depends testIsArtifactAware
  */
 public function testSettingArtifactAppliesToConsequences()
 {
     $artifact = \Mockery::mock('Havvg\\Component\\Lifecycle\\Artifact\\ArtifactInterface');
     $consequence = \Mockery::spy('Havvg\\Component\\Lifecycle\\Consequence\\ConsequenceInterface, Havvg\\Component\\Lifecycle\\Artifact\\ArtifactAwareInterface');
     $collection = new ConsequenceCollection();
     $collection->addConsequence($consequence);
     $collection->setArtifact($artifact);
     $consequence->shouldHaveReceived('setArtifact')->once()->with($artifact);
 }
 public function testAnEventDoesGetFiredWhenTheModelIsAPushable()
 {
     $dispatcher = m::spy(Dispatcher::class);
     $dispatcher->shouldReceive('fire')->times(5);
     $manager = new PushableManager($dispatcher);
     $manager->created(new DummyPushableModel());
     $manager->updated(new DummyPushableModel());
     $manager->deleted(new DummyPushableModel());
     $manager->attached(new DummyPushableModel());
     $manager->detached(new DummyPushableModel());
 }
 public function testSuccessfulRegistration()
 {
     $observer = m::spy(RegistrationObserverInterface::class);
     Recaptcha::shouldReceive('check')->once()->andReturn(true);
     $this->service->registerUser(['firstName' => 'Kirk', 'lastName' => 'Bushell', 'email' => '*****@*****.**', 'password' => '123456', 'password_confirmation' => '123456', 'g-recaptcha-response' => 'oiajsdlkjasdljksadf'], $observer);
     $user = $this->userRepository->getAll()->first();
     // Assert
     $observer->shouldHaveReceived('onSuccess')->once();
     $this->assertNotNull($user);
     $this->assertNotNull($user->confirmationToken);
 }
 /**
  * @return Application
  */
 private function getApplication()
 {
     if (!$this->application) {
         $app = new Application();
         require __DIR__ . '/../../../app/app.php';
         $app['logger'] = Mockery::spy('Psr\\Log\\LoggerInterface');
         $app['debug'] = true;
         $this->application = $app;
     }
     return $this->application;
 }
Example #20
0
 /**
  * @depends testAddCondition
  * @depends testAddConsequence
  */
 public function testSetArtifactOnConditionsAndConsequences()
 {
     $artifact = \Mockery::mock('Havvg\\Component\\Lifecycle\\Artifact\\ArtifactInterface');
     $condition = \Mockery::spy('Havvg\\Component\\Lifecycle\\Condition\\ConditionInterface, Havvg\\Component\\Lifecycle\\Artifact\\ArtifactAwareInterface');
     $consequence = \Mockery::spy('Havvg\\Component\\Lifecycle\\Consequence\\ConsequenceInterface, Havvg\\Component\\Lifecycle\\Artifact\\ArtifactAwareInterface');
     $event = new Event();
     $event->addCondition($condition);
     $event->addConsequence($consequence);
     $event->setArtifact($artifact);
     $condition->shouldHaveReceived('setArtifact')->once()->with($artifact);
     $consequence->shouldHaveReceived('setArtifact')->once()->with($artifact);
 }
Example #21
0
 /**
  * @depends testTriggerEvent
  */
 public function testTriggerEventCollection()
 {
     $dispatcher = \Mockery::spy('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $event = \Mockery::mock('Havvg\\Component\\Lifecycle\\Event\\EventInterface');
     $collection = new EventCollection();
     $collection->addEvent($event);
     $trigger = new EventTrigger($dispatcher);
     $trigger->all($collection);
     $dispatcher->shouldHaveReceived('dispatch')->once()->with(LifecycleEvents::EVENT_TRIGGERED, \Mockery::on(function ($actual) use($event) {
         return PHPUnit::evaluate($actual, PHPUnit::isInstanceOf('Havvg\\Component\\Lifecycle\\Event\\Runtime\\EventTriggeredEvent')) && PHPUnit::evaluate($actual->getEvent(), PHPUnit::equalTo($event));
     }));
 }
 public function testCommandHandling()
 {
     $repository = m::spy(UserRepositoryInterface::class);
     $account = m::mock(Account::class);
     $eventDispatcher = m::spy(EventDispatcher::class);
     $commandHandler = new RegisterUserCommandHandler($repository, $eventDispatcher);
     $command = new RegisterUserCommand('Kirk', 'Bushell', '*****@*****.**', 'lijsdflkjsdf', 'lkajsdflkjsdf', 'kjhasdfkjhasdf');
     CurrentAccount::shouldReceive('get')->once()->andReturn($account);
     $account->shouldReceive('addUser')->once();
     $this->assertNotNull($commandHandler->handle($command));
     $repository->shouldHaveReceived('save')->once();
     $eventDispatcher->shouldHaveReceived('dispatch')->once();
 }
 public function test_it_logs_the_user_in()
 {
     $providerAlias = 'twitbook';
     $socialnormUser = new SocialNorm\User([]);
     $callback = function () {
     };
     $redirector = $this->buildRedirector();
     $authenticator = M::spy('AdamWathan\\EloquentOAuth\\Authenticator');
     $socialnorm = M::mock('SocialNorm\\SocialNorm');
     $socialnorm->shouldReceive('getUser')->with($providerAlias)->andReturn($socialnormUser);
     $oauth = new OAuthManager($redirector, $authenticator, $socialnorm);
     $oauth->login($providerAlias, $callback);
     $authenticator->shouldHaveReceived('login')->with($providerAlias, $socialnormUser, $callback, false);
 }
 public function testExecution()
 {
     $command = m::mock('Tectonic\\Application\\Commanding\\Command');
     $container = m::mock('Illuminate\\Container\\Container')->makePartial();
     $translator = m::mock('Tectonic\\Application\\Commanding\\CommandTranslator')->makePartial();
     $logger = m::spy('Illuminate\\Log\\Writer');
     $translator->shouldReceive('getCommandHandler')->with($command)->andReturn('handler');
     $container->shouldReceive('make')->once()->with('handler')->andReturn($container);
     $container->shouldReceive('handle')->once()->with($command)->andReturn('execution result');
     $commandBus = new DefaultCommandBus($container, $translator, $logger);
     $response = $commandBus->execute($command);
     $this->assertEquals($response, 'execution result');
     $logger->shouldHaveReceived('info')->once();
 }
Example #25
0
 public function expectsEvents($events)
 {
     $this->events = is_array($events) ? $events : func_get_args();
     $mock = Mockery::spy('Illuminate\\Contracts\\Events\\Dispatcher');
     $mock->shouldReceive('fire')->andReturnUsing(function ($called) {
         foreach ($this->events as $key => $event) {
             if (is_string($called) && $called === $event || is_string($called) && is_subclass_of($called, $event) || is_object($called) && $called instanceof $event) {
                 unset($this->events[$key]);
             }
         }
     });
     App::instance('events', $mock);
     return $this;
 }
 public function testOnSuccessfulLogin()
 {
     // Arrange
     $observer = m::spy(AuthenticationResponderInterface::class);
     // Create a new user.
     $user = $this->createTempUser();
     // Associate user with this account.
     $currentAccount = CurrentAccount::get();
     DB::table('account_user')->insert(['account_id' => $currentAccount->id, 'user_id' => $user->id]);
     // Act (User not associated with current account, so it should cause a UserAccountAssociation exception)
     $this->service->login(['email' => '*****@*****.**', 'password' => 'password', 'remember' => false], $observer);
     // Assert.
     $this->assertSame(1, (int) $user->id);
     $observer->shouldHaveReceived('onSuccess')->once();
 }
Example #27
0
 public function testOnSuccess()
 {
     // Arrange
     $user = $this->createTempUser();
     $observer = m::spy(UserProfileResponder::class);
     $testData = ['firstName' => 'Test', 'lastName' => 'User', 'email' => '*****@*****.**', 'password' => '', 'passwordConfirmation' => ''];
     // Act
     $this->be($user);
     // Set logged in user
     $this->service->updateProfile($testData, $observer);
     // Assert.
     $observer->shouldHaveReceived('onSuccess')->once();
     $resultUser = App::make(UserRepositoryInterface::class)->getOneBy('id', $user->id);
     $this->assertSame($resultUser->email, $testData['email']);
 }
 public function setUp()
 {
     $faker = Factory::create();
     $this->userId = new ApplicationUserId($faker->uuid);
     $this->userName = $faker->userName;
     $this->language = $faker->countryISOAlpha3;
     $this->account = \Mockery::mock(Account::class);
     $this->user = \Mockery::mock(SourcedUser::class);
     $this->command = CreateUserCommand::create($this->userId, $this->user, $this->language);
     $this->userFactory = \Mockery::mock(UserFactory::class);
     $this->accountFactory = \Mockery::mock(AccountFactory::class);
     $this->userRepository = \Mockery::spy(UserEventSourcedRepository::class);
     $this->errorHandler = \Mockery::spy(ErrorEventHandler::class);
     $this->serviceUnderTest = new MessageAppCommandHandler($this->userFactory, $this->userRepository, $this->accountFactory, $this->errorHandler);
 }
 public function test_if_nothing_is_returned_from_the_callback_the_found_or_created_user_is_used()
 {
     $providerAlias = 'provider';
     $userDetails = new SocialNormUser([]);
     $foundUser = M::mock('Illuminate\\Contracts\\Auth\\Authenticatable')->shouldIgnoreMissing();
     $otherUser = M::mock('Illuminate\\Contracts\\Auth\\Authenticatable')->shouldIgnoreMissing();
     $auth = M::spy();
     $users = M::spy(['findByIdentity' => $foundUser]);
     $identities = M::spy(['userExists' => true, 'getByProvider' => new OAuthIdentity()]);
     $authenticator = new Authenticator($auth, $users, $identities);
     $authenticator->login('provider', $userDetails, function () {
         return;
     });
     $users->shouldNotHaveReceived('create');
     $users->shouldHaveReceived('store')->with($foundUser);
     $identities->shouldHaveReceived('store');
     $auth->shouldHaveReceived('login')->with($foundUser);
 }
 public function test_login_uses_existing_user_if_matching_user_exists()
 {
     $providerAlias = 'provider';
     $auth = M::spy();
     $users = M::spy();
     $identities = M::spy();
     $userDetails = new SocialNormUser([]);
     $user = M::mock('Illuminate\\Contracts\\Auth\\Authenticatable')->shouldIgnoreMissing();
     $identities->shouldReceive('userExists')->andReturn(true);
     $identities->shouldReceive('getByProvider')->andReturn(new OAuthIdentity());
     $users->shouldReceive('findByIdentity')->andReturn($user);
     $authenticator = new Authenticator($auth, $users, $identities);
     $authenticator->login('provider', $userDetails);
     $users->shouldNotHaveReceived('create');
     $users->shouldHaveReceived('store')->with($user);
     $identities->shouldHaveReceived('store');
     $auth->shouldHaveReceived('login')->with($user);
 }