/** * Do the Artisan commands fire? */ public function testCommands() { $self = $this; $this->prepareSpecify(); $this->specify('Boots', function () use($self) { $target = $self->getProvider(['package']); $target->shouldReceive('package'); $target->boot(); }); $this->prepareSpecify(); $this->specify('Identifies provisions', function () use($self) { $target = $self->getProvider(); verify($target->provides())->notEmpty(); }); $this->prepareSpecify(); $this->specify('Binds to application', function () use($self) { App::shouldReceive('bind')->with('/^toolbox\\.commands\\./', Mockery::on(function ($closure) { $command = $closure(); verify_that('is a command', is_a($command, 'Illuminate\\Console\\Command')); return true; })); Event::shouldReceive('listen')->with('toolbox.build', Mockery::on(function ($closure) { $app = Mockery::mock('Illuminate\\Console\\Application[call]'); $app->shouldReceive('call'); $command = $closure($app); return true; })); $target = $self->getProvider(['commands']); $target->shouldReceive('commands')->with(Mockery::type('array')); $target->register(); }); }
public function testItRunAuditingEnableConsole() { App::shouldReceive('runningInConsole')->once()->andReturn(true); Config::shouldReceive('get')->once()->with('auditing.audit_console')->andReturn(true); $model = new AuditableModel(); $this->assertTrue($model->isAuditEnabled()); }
/** * Integration Test. */ public function testPushCommand() { $configuration_file = ['bypass' => false, 'default' => 'AwsS3', 'url' => 'https://s3.amazonaws.com', 'threshold' => 10, 'providers' => ['aws' => ['s3' => ['region' => 'us-standard', 'version' => 'latest', 'buckets' => ['my-bucket-name' => '*'], 'acl' => 'public-read', 'cloudfront' => ['use' => false, 'cdn_url' => ''], 'metadata' => [], 'expires' => gmdate('D, d M Y H:i:s T', strtotime('+5 years')), 'cache-control' => 'max-age=2628000', 'version' => '']]], 'include' => ['directories' => [__DIR__], 'extensions' => [], 'patterns' => []], 'exclude' => ['directories' => [], 'files' => [], 'extensions' => [], 'patterns' => [], 'hidden' => true]]; $m_consol = M::mock('Symfony\\Component\\Console\\Output\\ConsoleOutput'); $m_consol->shouldReceive('writeln')->atLeast(1); $finder = new \Vinelab\Cdn\Finder($m_consol); $asset = new \Vinelab\Cdn\Asset(); $provider_factory = new \Vinelab\Cdn\ProviderFactory(); $m_config = M::mock('Illuminate\\Config\\Repository'); $m_config->shouldReceive('get')->with('cdn')->once()->andReturn($configuration_file); $helper = new \Vinelab\Cdn\CdnHelper($m_config); $m_console = M::mock('Symfony\\Component\\Console\\Output\\ConsoleOutput'); $m_console->shouldReceive('writeln')->atLeast(2); $m_validator = M::mock('Vinelab\\Cdn\\Validators\\Contracts\\ProviderValidatorInterface'); $m_validator->shouldReceive('validate'); $m_helper = M::mock('Vinelab\\Cdn\\CdnHelper'); $m_spl_file = M::mock('Symfony\\Component\\Finder\\SplFileInfo'); $m_spl_file->shouldReceive('getPathname')->andReturn('vinelab/cdn/tests/Vinelab/Cdn/AwsS3ProviderTest.php'); $m_spl_file->shouldReceive('getRealPath')->andReturn(__DIR__ . '/AwsS3ProviderTest.php'); // partial mock $p_aws_s3_provider = M::mock('\\Vinelab\\Cdn\\Providers\\AwsS3Provider[connect]', array($m_console, $m_validator, $m_helper)); $m_s3 = M::mock('Aws\\S3\\S3Client')->shouldIgnoreMissing(); $m_s3->shouldReceive('factory')->andReturn('Aws\\S3\\S3Client'); $m_command = M::mock('Aws\\Command'); $m_s3->shouldReceive('getCommand')->andReturn($m_command); $m_s3->shouldReceive('execute'); $p_aws_s3_provider->setS3Client($m_s3); $p_aws_s3_provider->shouldReceive('connect')->andReturn(true); \Illuminate\Support\Facades\App::shouldReceive('make')->once()->andReturn($p_aws_s3_provider); $cdn = new \Vinelab\Cdn\Cdn($finder, $asset, $provider_factory, $helper); $result = $cdn->push(); assertEquals($result, true); }
/** * @expectedException \Publiux\laravelcdn\Exceptions\MissingConfigurationException */ public function testCreateThrowsExceptionWhenMissingDefaultConfiguration() { $configurations = ['default' => '']; $m_aws_s3 = M::mock('Publiux\\laravelcdn\\Providers\\AwsS3Provider'); \Illuminate\Support\Facades\App::shouldReceive('make')->once()->andReturn($m_aws_s3); $this->provider_factory->create($configurations); }
/** * @test */ public function it_should_fire_job_with_unresolvable_models() { /** * * Set * */ App::shouldReceive('make')->with('menthol.flexible.proxy', Mockery::any())->once()->andReturn('mock'); $app = m::mock('Illuminate\\Foundation\\Application'); $config = m::mock('Menthol\\Flexible\\Config'); $logger = m::mock('Monolog\\Logger'); $job = m::mock('Illuminate\\Queue\\Jobs\\Job'); $models = ['Husband:99999']; /** * * Expectation * */ $logger->shouldReceive('info')->with('Indexing Husband with ID: 99999'); $logger->shouldReceive('error')->with('Indexing Husband with ID: 99999 failed: No query results for model [Husband].'); $config->shouldReceive('get')->with('logger', 'menthol.flexible.logger')->andReturn('menthol.flexible.logger'); $app->shouldReceive('make')->with('menthol.flexible.logger')->andReturn($logger); $job->shouldReceive('delete')->once(); $job->shouldReceive('release')->with(60)->once(); /** * * Assertion * */ with(new ReindexJob($app, $config))->fire($job, $models); }
/** * @test */ public function it_should_transform() { /** * * Set * */ $husband = m::mock('Husband')->makePartial(); /** * * Expectation * */ $husband->shouldReceive('load->toArray')->once()->andReturn('mock'); $config = m::mock('Menthol\\Flexible\\Config'); App::shouldReceive('make')->with('Menthol\\Flexible\\Config')->andReturn($config); $config->shouldReceive('get')->with('/paths\\..*/')->once(); /** * * Assertion * */ $transformed = $husband->transform(true); $this->assertEquals('mock', $transformed); }
public function testInstallationAlreadyCompleted() { $this->mockAccountManagementService->shouldReceive('totalNumberOfAccounts')->andReturn(1); App::shouldReceive('abort')->with(404)->once(); $this->middleware->handle('request', function () { }); }
/** * @test */ public function it_should_bind_index() { /** * Set */ App::clearResolvedInstances(); App::shouldReceive('make')->with('menthol.flexible.index', m::any())->once()->andReturn('mock'); App::shouldReceive('make')->with('Elasticsearch')->twice()->andReturn('mock'); $config = m::mock('Menthol\\Flexible\\Config'); App::shouldReceive('make')->with('Menthol\\Flexible\\Config')->once()->andReturn($config); $config->shouldReceive('get')->with('elasticsearch.index_prefix', '')->andReturn(''); $model = m::mock('Illuminate\\Database\\Eloquent\\Model'); $model->shouldReceive('getTable')->once()->andReturn('mockType'); $app = m::mock('LaravelApp'); $proxy = m::mock('Menthol\\Flexible\\Proxy', [$model]); $sp = m::mock('Menthol\\Flexible\\FlexibleServiceProvider[bindIndex]', [$app]); /** * Expectation */ $app->shouldReceive('bind')->once()->andReturnUsing(function ($name, $closure) use($app, $proxy) { $this->assertEquals('menthol.flexible.index', $name); $this->assertInstanceOf('Menthol\\Flexible\\Index', $closure($app, ['proxy' => $proxy, 'name' => 'name'])); }); /** * Assertion */ $sp->bindIndex(); }
/** @test */ public function is_active_calls_is_active_method() { $activeMock = Mockery::mock(Active::class); $activeMock->shouldReceive('isActive')->once()->with(['foo'])->andReturn('bar'); App::shouldReceive('make')->once()->with('active')->andReturn($activeMock); $result = is_active('foo'); $this->assertEquals('bar', $result); }
/** @test */ function it_instantiates_the_transformer_if_a_model_uses_the_trait_and_was_defined_in_the_config() { $user = $this->makeUsers(1, true); $user->unsetTransformerProperty(); Config::shouldReceive('has')->twice()->with('transformers.transformers')->andReturn(true); Config::shouldReceive('get')->twice()->with('transformers.transformers')->andReturn([User::class => UserTransformer::class]); App::shouldReceive('make')->once()->with(UserTransformer::class)->andReturn(new UserTransformer()); $this->assertInstanceOf(UserTransformer::class, $user->getTransformer()); }
public function testGetService() { // Arrange App::shouldReceive('make')->once()->with(\Exception::class)->andReturn(new \Exception()); $stub = new ModelStub(); // Act $exception = $stub->exception; // Assert $this->assertInstanceOf(\Exception::class, $exception); }
/** @test */ function it_transforms_nested_relations() { $this->makeUserWithPosts(); $user = User::first(); $transformer = new UserTransformer(); App::shouldReceive('make')->once()->with(PostTransformer::class)->andReturn(new PostTransformer()); App::shouldReceive('make')->once()->with(TagTransformer::class)->andReturn(new TagTransformer()); $transformedData = $transformer->with('posts.tags')->transform($user); $this->assertCount(3, $transformedData['posts']); $this->assertCount(4, $transformedData['posts'][0]['tags']); }
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 test_handle_action() { $params = ['model' => $this->user, 'id' => null, 'parent_data' => [], 'additional_assigns' => [], 'belongsTo' => null]; App::shouldReceive('make')->once()->with('http_method', $params)->andReturn($this->http_method); $this->http_method->shouldReceive('handleRequest')->andReturn('json string'); //since api base controller is protected, we have to use reflection magic $reflector = new ReflectionClass(new ApiBaseController()); $handleAction = $reflector->getMethod('handleAction'); $handleAction->setAccessible(true); $handleAction->invoke(new ApiBaseController(), $this->user); }
public function testFormValidation() { $route = m::mock('Route'); $route->shouldReceive('getAction')->andReturn(array('controller' => 'indexRule')); $request = m::mock('Request'); $request->shouldReceive('all')->andReturn(array('name' => 'test')); App::shouldReceive('make')->andReturn(new FormStub()); Validator::shouldReceive('make')->andReturn(new ValidatorClass($this->getRealTranslator(), $request->all(), array('name' => array('required', 'min:5')))); $controller = new RESTControllerStub(); $controller->validateRequest($route, $request); }
protected function mockAws() { $credentialsTestArray = ['credentials' => 'test']; // $this->serviceBuilder = Aws::factory(); // $this->serviceBuilder->enableFacades(); // AWSFacade::setFacadeApplication($this->app); $this->mockAws = m::mock('Aws'); $this->dynamoDbClient = m::mock('DynamoDbClient'); App::shouldReceive('make')->with('aws')->once()->andReturn($this->dynamoDbClient); $this->dynamoDbClient->shouldReceive('get')->once()->with('DynamoDb')->andReturnSelf(); $this->dynamoDbClient->shouldReceive('getCredentials')->once()->andReturn($credentialsTestArray); }
/** * @test */ public function it_should_reindex_on_model_save() { /** * * Expectation * */ Facade::clearResolvedInstances(); $proxy = m::mock('Iverberk\\Larasearch\\Proxy'); $proxy->shouldReceive('shouldIndex')->andReturn(true); App::shouldReceive('make')->with('iverberk.larasearch.proxy', m::type('Illuminate\\Database\\Eloquent\\Model'))->andReturn($proxy); Config::shouldReceive('get')->with('/^larasearch::reversedPaths\\.Husband$/', array())->once()->andReturn(['', 'wife', 'children', 'children.toys']); Queue::shouldReceive('push')->with('Iverberk\\Larasearch\\Jobs\\ReindexJob', ['Husband:2', 'Wife:2', 'Child:2', 'Toy:2'])->once(); /** * * * Assertion * */ $husband = \Husband::find(2); with(new Observer())->saved($husband); /** * * Expectation * */ Facade::clearResolvedInstances(); $proxy = m::mock('Iverberk\\Larasearch\\Proxy'); $proxy->shouldReceive('shouldIndex')->andReturn(true); App::shouldReceive('make')->with('iverberk.larasearch.proxy', m::type('Illuminate\\Database\\Eloquent\\Model'))->andReturn($proxy); Config::shouldReceive('get')->with('/^larasearch::reversedPaths\\.Toy$/', array())->once()->andReturn(['', 'children', 'children.mother.husband', 'children.mother']); Queue::shouldReceive('push')->with('Iverberk\\Larasearch\\Jobs\\ReindexJob', ['Toy:2', 'Child:8', 'Child:2', 'Husband:8', 'Husband:2', 'Wife:8', 'Wife:2'])->once(); /** * * * Assertion * */ $toy = \Toy::find(2); with(new Observer())->saved($toy); }
public function it_can_use_golomt() { App::shouldReceive('make')->with('Selmonal\\Payment\\Gateways\\Golomt\\Gateway')->andReturn($gateway = m::mock('Selmonal\\Payment\\Gateways\\Golomt\\Gateway')); $this->using('golomt'); $this->getGateway()->shouldEqual($gateway); }
/** * Construct an Index mock * * @return array */ private function getMocks($index_prefix = '') { /** * * Expectation * */ Facade::clearResolvedInstances(); $client = m::mock('Elasticsearch\\Client'); $config = m::mock('Menthol\\Flexible\\Config'); App::shouldReceive('make')->with('Elasticsearch')->andReturn($client); App::shouldReceive('make')->with('Menthol\\Flexible\\Config')->andReturn($config); $config->shouldReceive('get')->with('elasticsearch.index_prefix', '')->andReturn($index_prefix); $proxy = m::mock('Menthol\\Flexible\\Proxy'); $proxy->shouldReceive('getModel->getTable')->andReturn('Husband'); $index = m::mock('Menthol\\Flexible\\Index', [$proxy], [m::BLOCKS => ['setName', 'setProxy']])->makePartial(); return [$index, $proxy, $client, $config]; }
/** * @test */ public function it_should_fire_with_config_not_confirmed() { /** * Set * * @var \Mockery\Mock $command */ $command = m::mock('Menthol\\Flexible\\Commands\\PathsCommand')->makePartial(); $command->shouldAllowMockingProtectedMethods(); File::clearResolvedInstance('files'); File::shouldReceive('exists')->once()->andReturn(false); App::shouldReceive('make')->andReturn(true); /** * Expectation */ $command->shouldReceive('getLaravel')->once()->andReturn(true); $command->shouldReceive('argument')->with('model')->once()->andReturn(['Husband']); $command->shouldReceive('option')->with('dir')->once()->andReturn([__DIR__ . '/../../../Support/Stubs']); $command->shouldReceive('option')->with('write-config')->once()->andReturn(true); $command->shouldReceive('confirm')->once()->andReturn(false); $command->shouldReceive('compilePaths', 'error', 'call', 'info')->andReturn(true); /* |------------------------------------------------------------ | Assertion |------------------------------------------------------------ */ $command->fire(); }
public function testLocaleSetup() { CurrentLocale::shouldReceive('code')->once()->andReturn('code'); App::shouldReceive('setLocale')->with('code')->once(); with(new LocaleComposer())->compose(); }
public function testCallingMapperAsArrayWithStringName() { $mPost = M::mock('Post'); $mPost->shouldReceive('setAttribute')->passthru(); $mPost->id = 1; $mPost->text = 'Enim provident tempore reiciendis quit qui.'; $mPost->active = true; $mPost->shouldReceive('getAttribute')->passthru(); $expected = ['status' => 200, 'data' => ['id' => 1, 'text' => 'Enim provident tempore reiciendis quit qui.', 'active' => true]]; $this->response_handler->setMapperNamespace('Vinelab\\Api\\Tests\\'); $mapper = ['DummyMapper', 'mapDatThing']; $mMapper = M::mock('Vinelab\\Api\\Tests\\DummyMapper'); $mMapper->shouldReceive('mapDatThing')->once()->with($mPost)->andReturn($expected['data']); App::shouldReceive('make')->once()->with('Vinelab\\Api\\Tests\\DummyMapper')->andReturn($mMapper); $response = M::mock('Illuminate\\Http\\Response'); $response->shouldReceive('getData')->once()->andReturn($expected); Response::shouldReceive('json')->once()->with($expected, 200, [], 0)->andReturn($response); $result = $this->response_handler->content($mapper, $mPost); $this->assertInternalType('array', $result); $this->assertEquals($expected, $result); }
/** * {@inheritdoc} */ public function setUp() { App::shouldReceive('runningInConsole')->andReturn(true); Config::shouldReceive('get')->with('auditing.audit_console')->andReturn(true); parent::setUp(); }
/** * @test * @expectedException \BadMethodCallException */ public function it_should_not_call_methods_on_the_proxy() { /** * * Expectation * */ App::clearResolvedInstance('app'); App::shouldReceive('make')->with('Elasticsearch')->andReturn(true); App::shouldReceive('make')->with('iverberk.larasearch.index', m::type('array'))->andReturn(true); /** * * Assertion * */ // Overrule the proxy defined in previous tests am::double('Husband', ['getProxy' => new Proxy(new Husband())]); // Call a non existing method \Husband::bogus('*'); }
/** * Construct an Index mock * * @return array */ private function getMocks($index_prefix = null) { /** * * Expectation * */ Facade::clearResolvedInstances(); Config::shouldReceive('get')->with('larasearch::elasticsearch.index_prefix', '')->andReturn($index_prefix); $client = m::mock('Elasticsearch\\Client'); App::shouldReceive('make')->with('Elasticsearch')->andReturn($client); $proxy = m::mock('Iverberk\\Larasearch\\Proxy'); $proxy->shouldReceive('getModel->getTable')->andReturn('Husband'); $index = m::mock('Iverberk\\Larasearch\\Index', [$proxy])->makePartial(); return [$index, $proxy, $client]; }
public function test_instantiate() { App::shouldReceive('make')->with('path.public')->andReturn('/var/www/uploads'); $fs = new Filesystem(); $this->assertEquals('/var/www/uploads', $fs->root); }
public function testAnalyticsReturnsNullIfNotInProduction() { App::shouldReceive('environment')->andReturn('local'); Settings::shouldReceive('get')->with('analytics')->andReturn('test'); $this->assertEquals('', Helpers::analytics()); }
/** * @test */ public function it_should_bind_index() { /** * Set */ App::shouldReceive('make')->with('iverberk.larasearch.index', Mockery::any())->once()->andReturn('mock'); App::shouldReceive('make')->with('Elasticsearch')->twice()->andReturn('mock'); $model = m::mock('Illuminate\\Database\\Eloquent\\Model'); $model->shouldReceive('getTable')->once()->andReturn('mockType'); $app = m::mock('LaravelApp'); $proxy = m::mock('Iverberk\\Larasearch\\Proxy', [$model]); $sp = m::mock('Iverberk\\Larasearch\\LarasearchServiceProvider[bindIndex]', [$app]); /** * Expectation */ $app->shouldReceive('bind')->once()->andReturnUsing(function ($name, $closure) use($app, $proxy) { assertEquals('iverberk.larasearch.index', $name); assertInstanceOf('Iverberk\\Larasearch\\Index', $closure($app, ['proxy' => $proxy, 'name' => 'name'])); }); /** * Assertion */ $sp->bindIndex(); }
/** * @test */ public function it_can_reindex_when_alias_exists() { /** * * Set * */ $indexDouble = am::double('Menthol\\Flexible\\Index', ['refresh' => null, 'clean' => null, 'updateAliases' => null, 'getAlias' => ['mockIndex' => 'aliases']]); $indexMock = m::mock('Menthol\\Flexible\\Index'); $operations[] = ['add' => ['alias' => 'Husband', 'index' => 'Husband_9999'], 'remove' => ['alias' => 'Husband', 'index' => 'mockIndex']]; $actions[] = ['actions' => $operations]; $test = $this; /** * * Expectation * */ $this->index->shouldReceive('getName')->andReturn('Husband'); $indexMock->shouldReceive('create')->once()->andReturn(); $indexMock->shouldReceive('aliasExists')->once()->andReturn(true); $indexMock->shouldReceive('import')->andReturn(); App::shouldReceive('make')->with('menthol.flexible.index', ['name' => 'Husband_9999', 'proxy' => $this->proxy])->andReturn($indexMock); /** * * Assertion * */ $this->proxy->reindex(); $indexDouble->verifyInvoked('refresh', 'Husband'); $indexDouble->verifyInvoked('clean', 'Husband'); $indexDouble->verifyInvoked('updateAliases', function ($calls) use($test, $actions) { $test->assertEquals($actions, $calls[0]); }); }
/** * @test */ public function it_should_reindex_on_model_delete() { /** * * Expectation * */ Facade::clearResolvedInstances(); Queue::shouldReceive('push')->with('Menthol\\Flexible\\Jobs\\DeleteJob', ['Husband:2'])->once(); $config = m::mock('Menthol\\Flexible\\Config'); App::shouldReceive('make')->with('Menthol\\Flexible\\Config')->andReturn($config); $config->shouldReceive('get')->with('/^reversedPaths\\..*$/', [])->once()->andReturn(['', 'wife', 'children', 'children.toys']); Queue::shouldReceive('push')->with('Menthol\\Flexible\\Jobs\\ReindexJob', ['Wife:2', 'Child:2', 'Toy:2'])->once(); $husband = \Husband::find(2); with(new Observer())->deleted($husband); }