public function setUp() { // set up config Config::shouldReceive('get')->zeroOrMoreTimes()->with("datatable::engine")->andReturn(array('exactWordSearch' => false)); $this->collection = new Collection(); $this->engine = new CollectionEngine($this->collection); }
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()); }
public function testGetOwner() { Config::shouldReceive('get')->once()->with('auth.model')->andReturn('TestUser'); $stub = m::mock('TestUserTeamTraitStub[hasOne]'); $stub->shouldReceive('hasOne')->once()->with('User', 'user_id', 'owner_id')->andReturn([]); $this->assertEquals([], $stub->owner()); }
public function testRoles() { /* |------------------------------------------------------------ | Set |------------------------------------------------------------ */ $belongsToMany = new stdClass(); $user = m::mock('HasRoleUser')->makePartial(); $app = m::mock('app')->shouldReceive('instance')->getMock(); $config = m::mock('config'); Config::setFacadeApplication($app); Config::swap($config); /* |------------------------------------------------------------ | Expectation |------------------------------------------------------------ */ $user->shouldReceive('belongsToMany')->with('role_table_name', 'assigned_roles_table_name', 'user_id', 'role_id')->andReturn($belongsToMany)->once(); Config::shouldReceive('get')->once()->with('entrust.role')->andReturn('role_table_name'); Config::shouldReceive('get')->once()->with('entrust.role_user_table')->andReturn('assigned_roles_table_name'); /* |------------------------------------------------------------ | Assertion |------------------------------------------------------------ */ $this->assertSame($belongsToMany, $user->roles()); }
protected function setupBuilder($showAllRecords = false) { Config::shouldReceive('get'); $cache = m::mock('stdClass'); $driver = m::mock('stdClass'); $data = [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']]; $builder = m::mock('Illuminate\\Database\\Query\\Builder'); $builder->shouldReceive('select')->once()->with(['id', 'name'])->andReturn($builder); $builder->shouldReceive('from')->once()->with('users')->andReturn($builder); $builder->shouldReceive('get')->once()->andReturn($data); $builder->columns = ['id', 'name']; $builder->select(['id', 'name'])->from('users'); // ****************************** // Datatables::of() mocks // ****************************** $builder->shouldReceive('getConnection')->andReturn(m::mock('Illuminate\\Database\\Connection')); $builder->shouldReceive('toSql')->times(6)->andReturn('select id, name from users'); $builder->getConnection()->shouldReceive('raw')->once()->andReturn('select \'1\' as row_count'); $builder->shouldReceive('select')->once()->andReturn($builder); $builder->getConnection()->shouldReceive('raw')->andReturn('(select id, name from users) count_row_table'); $builder->shouldReceive('select')->once()->andReturn($builder); $builder->getConnection()->shouldReceive('table')->times(2)->andReturn($builder); $builder->shouldReceive('getBindings')->times(2)->andReturn([]); $builder->shouldReceive('setBindings')->times(2)->with([])->andReturn($builder); // ****************************** // Datatables::make() mocks // ****************************** if (!$showAllRecords) { $builder->shouldReceive('skip')->once()->andReturn($builder); $builder->shouldReceive('take')->once()->andReturn($builder); } $builder->shouldReceive('count')->times(2)->andReturn(2); return $builder; }
protected function setupBuilder($showAllRecords = false) { Config::shouldReceive('get'); $cache = m::mock('stdClass'); $driver = m::mock('stdClass'); $data = [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar']]; $builder = m::mock('Illuminate\\Database\\Query\\Builder'); $builder->shouldReceive('getGrammar')->once()->andReturn($builder); $builder->shouldReceive('getTablePrefix')->once()->andReturn($builder); $builder->shouldReceive('getConnection')->andReturn(m::mock('Illuminate\\Database\\Connection')); $builder->getConnection()->shouldReceive('getDriverName')->once()->andReturn('dbdriver'); // setup builder $builder->shouldReceive('select')->once()->with(['id', 'name'])->andReturn($builder); $builder->shouldReceive('from')->once()->with('users')->andReturn($builder); $builder->columns = ['id', 'name']; $builder->select(['id', 'name'])->from('users'); // count total records $builder->shouldReceive('toSql')->times(2)->andReturn('select id, name from users'); $builder->shouldReceive('select')->once()->andReturn($builder); $builder->getConnection()->shouldReceive('raw')->once()->andReturn('select \'1\' as row_count'); $builder->getConnection()->shouldReceive('table')->once()->andReturn($builder); $builder->getConnection()->shouldReceive('raw')->andReturn('(select id, name from users) count_row_table'); $builder->shouldReceive('toSql')->once()->andReturn('select id, name from users'); $builder->shouldReceive('getBindings')->once()->andReturn([]); $builder->shouldReceive('setBindings')->once()->with([])->andReturn($builder); $builder->shouldReceive('count')->once()->andReturn(2); // get data $builder->shouldReceive('get')->once()->andReturn($data); // pagination if (!$showAllRecords) { $builder->shouldReceive('skip')->once()->andReturn($builder); $builder->shouldReceive('take')->once()->andReturn($builder); } return $builder; }
public function testGetModelClassFoundation() { $class = 'C4tech\\Magic'; Config::shouldReceive('get')->with('upload.models.upload', 'upload.models.upload')->once()->andReturn('C4tech\\Silly'); Config::shouldReceive('get')->with('foundation.models.upload', 'C4tech\\Silly')->once()->andReturn($class); expect($this->repo->getModelClass())->equals($class); }
/** * @test */ public function it_creates_the_user_relationship() { Config::shouldReceive('get')->once()->with('eloquent-sentiment.user')->andReturn('UserClass'); $sentiment = m::mock(Sentiment::class)->makePartial(); $sentiment->shouldReceive('belongsTo')->once()->andReturn('ok'); $this->assertEquals($sentiment->user(), 'ok'); }
public function testToArrayJsonify() { $this->model->test_thing = 123; $this->model->shouldReceive('convertToCamelCase')->with(['test_thing' => 123])->once()->andReturn(false); Config::shouldReceive('get')->with('c4tech.jsonify_output', true)->once()->andReturn(true); expect($this->model->toArray())->false(); }
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 testPlaceholders() { $this->specify("placeholders are replaced with values of other validated fields", function () { $rules = ['a' => 'min:{{min}}']; $data = ['a' => 'abcd', 'min' => 3]; $this->assertTrue($this->makeValidator($rules, $data)->passes()); $data = ['a' => 'ab', 'min' => 3]; $this->assertFalse($this->makeValidator($rules, $data)->passes()); $rules = ['a' => '!min:{{min}}']; $data = ['a' => 'abcd', 'min' => 3]; $this->assertFalse($this->makeValidator($rules, $data)->passes()); $data = ['a' => 'ab', 'min' => 3]; $this->assertTrue($this->makeValidator($rules, $data)->passes()); }); $this->specify("placeholders are replaced with config values", function () { Config::shouldReceive('get')->with('app.min')->andReturn(3); $rules = ['a' => 'min:{{app.min}}']; $data = ['a' => 'abcd']; $this->assertTrue($this->makeValidator($rules, $data)->passes()); $data = ['a' => 'ab']; $this->assertFalse($this->makeValidator($rules, $data)->passes()); $rules = ['a' => '!min:{{app.min}}']; $data = ['a' => 'abcd']; $this->assertFalse($this->makeValidator($rules, $data)->passes()); $data = ['a' => 'ab']; $this->assertTrue($this->makeValidator($rules, $data)->passes()); }); }
/** * Test if a key is return if useSecureURLs is configured true */ public function testTrueSecureURL() { $expectedResult = 'my-key'; $glideConfig['useSecureURLs'] = true; Config::shouldReceive('get')->with('app.key')->andReturn($expectedResult); $result = $this->serviceProvider->getSignKey($glideConfig); $this->assertEquals($expectedResult, $result); }
protected function setUp() { // set up config Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper_datatable.engine")->andReturn(array('exactWordSearch' => false)); Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper_datatable.table")->andReturn(array('class' => 'table table-bordered', 'id' => '', 'options' => array("sPaginationType" => "full_numbers", "bProcessing" => false), 'callbacks' => array(), 'noScript' => false, 'table_view' => 'datatable::template', 'script_view' => 'datatable::javascript')); $this->dt = new Datatable(); $this->mock = Mockery::mock('Illuminate\\Database\\Query\\Builder'); }
/** @test */ public function it_generates_not_rewrite_url_if_config_value_is_false() { Config::shouldReceive('get')->once()->with("imgproxy::rewrite")->andReturn(false); URL::shouldReceive('to')->once()->with("packages/spescina/imgproxy/timthumb.php?w=100&h=70&zc=1&q=90&src=image/path/url.jpg")->andReturn("http://www.example.com/packages/spescina/imgproxy/timthumb.php?w=100&h=70&zc=1&q=90&src=image/path/url.jpg"); $imgProxy = new Imgproxy(); $url = $imgProxy->link("image/path/url.jpg", 100, 70); $this->assertEquals("http://www.example.com/packages/spescina/imgproxy/timthumb.php?w=100&h=70&zc=1&q=90&src=image/path/url.jpg", $url); }
public function testGetApiPrefix() { Config::shouldReceive('get')->with('andizzle/rest-framework::deprecated')->andReturn(array()); Config::shouldReceive('get')->with('andizzle/rest-framework::version')->andReturn('v1'); Request::shouldReceive('segments')->once()->andReturn(array('api', 'v1', 'test')); $server = new RestServer(); $this->assertEquals($server->getApiPrefix(), '/api/v1'); }
public function setUp() { Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper_datatable.engine")->andReturn(array('exactWordSearch' => false)); parent::setUp(); Config::shouldReceive('get')->zeroOrMoreTimes()->with("chumper_datatable.engine")->andReturn(array('exactWordSearch' => false)); $this->collection = Mockery::mock('Illuminate\\Support\\Collection'); $this->c = new CollectionEngine($this->collection); }
public function testTransformJsonSnake() { $key = 'key'; $default = 'default'; $request = Mockery::mock('C4tech\\Test\\Support\\Traits\\MockRequest[snakeJson]'); $request->shouldReceive('snakeJson')->with($key, $default)->once()->andReturn(true); Config::shouldReceive('get')->with('c4tech.snakify_json_input', true)->once()->andReturn(true); expect($request->transformJson($key, $default))->true(); }
public function testToArrayJsonify() { $model = $this->getModelMock(); $model->shouldAllowMockingProtectedMethods(); $model->test_thing = 123; $model->shouldReceive('convertToCamelCase')->with(['test_thing' => 123])->once()->andReturn(false); Config::shouldReceive('get')->with('c4tech.jsonify_output', true)->once()->andReturn(true); expect($model->toArray())->false(); }
/** @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 testCreateMethodNameDoesDefault() { $subject = Mockery::mock('C4tech\\Test\\RayEmitter\\Domain\\AggregateStub'); $key = 'blast_level'; $default = 'shrink'; $object = new AggregateStub(); Config::shouldReceive('get')->with('ray_emitter.blast_level', 'shrink')->once()->andReturn('shrink'); $create = $this->getMethod($subject, 'createMethodName'); expect($create->invoke($subject, $key, $object, $default))->equals('shrinkAggregateStub'); }
public function testFindUserByTokenOrFail() { $user = Mockery::mock(UserStub::class); $user->shouldReceive('getQualifiedKeyForToken')->andReturn(1); $token = (string) $this->getService()->generateTokenForUser($user); Config::shouldReceive('get')->twice()->with('laravel-jwt.issuer')->andReturn('Pascal Baljet Media'); Config::shouldReceive('get')->once()->with('laravel-jwt.model')->andReturn(UserStub::class); $user = $this->getService()->findUserByTokenOrFail($token); $this->assertInstanceOf(UserStub::class, $user); }
public function setUp() { $this->setUpSchemaFacade(); foreach ($this->migrations as $class) { $migration = new $class(); $migration->up(); $migration = null; } $this->tearDownFacades(); Model::unguard(); Config::shouldReceive('get')->with('auth.model', Mockery::any())->andReturn('TestUser'); }
public function testBuildLink() { Config::shouldReceive('get')->with('andizzle/rest-framework::page_limit')->andReturn('5'); REST::shouldReceive('getApiPrefix')->andReturn('api/v1'); $serializer = new HyperlinkedJSONSerializer(); $fooobj = new RESTModelStub(); $fooobj->id = 1; $fooobj->root = 'roots'; $collection = new Collection(); $collection->add($fooobj); $this->assertEquals('api/v1/roots/1', $serializer->buildLink($fooobj)); $this->assertEquals('api/v1/roots?ids=1', $serializer->buildLink($collection)); }
/** * Test fire method * * @test */ public function testFireMethod() { $packageCreator = m::mock('Elepunk\\Orchestrate\\PackageCreator'); $input = m::mock('Symfony\\Component\\Console\\Input\\InputInterface'); $output = m::mock('Symfony\\Component\\Console\\Output\\OutputInterface'); $command = m::mock('Illuminate\\Console\\Command'); $input->shouldReceive('bind')->once()->shouldReceive('isInteractive')->once()->andReturn(true)->shouldReceive('validate')->once()->shouldReceive('getArgument')->once()->andReturn('foo/bar'); Config::shouldReceive('get')->once()->andReturn('foobar'); $packageCreator->shouldReceive('create')->once(); $output->shouldReceive('writeln')->once()->with('<info>Orchestra Platform extension created. Run php artisan dump-autoload</info>'); $stub = new Command($packageCreator); $stub->run($input, $output); }
public function test_get_collection_on_a_nested_non_paginated_resource_get_request() { $apiQueryBuilders = [$this->joinsBuilder]; $input = array('joins' => [0 => 'accounts:users.id=accounts.user_id']); Config::shouldReceive('get')->once()->with('ranger::ranger.pagination.per_page')->andReturn(null); $this->requestContainer->shouldReceive('getInput')->once()->andReturn($input); $this->joinsBuilder->shouldReceive('buildQueryFromParameters')->once()->with($this->model, $input)->andReturn($this->builder); $this->requestContainer->shouldReceive('getParentAssociation')->twice()->andReturn(['user_id' => 1]); $this->requestContainer->shouldReceive('getTable')->once()->andReturn('accounts'); $this->builder->shouldReceive('where')->once()->with('accounts.user_id', '=', 1)->andReturn($this->builder); $this->builder->shouldReceive('get')->once()->andReturn($collection = m::mock('Illuminate\\Database\\Eloquent\\Builder')); $collection->shouldReceive('toArray')->once()->andReturn([]); (new CollectionQuery($apiQueryBuilders, $this->requestContainer))->executeQuery('get'); }
public function testSerializeNoEmbed() { Config::shouldReceive('get')->with('andizzle/rest-framework::page_limit')->andReturn('5'); Config::shouldReceive('get')->with('andizzle/rest-framework::serializer.embed-relations')->once()->andReturn(false); $obj = new RESTModelStub(); $obj->foo = 'bar'; $fooobj = new RESTModelStub(); $fooobj->id = 1; $fooobj->root = 'roots'; $collection = new Collection(); $obj->setSideLoads(array('foos')); $collection->push($fooobj); $obj->setRelation('foos', $collection); $serializer = new JSONSerializer(); $this->assertEquals(array('fred' => array('foo' => 'bar', 'foos' => array('1'))), $serializer->serialize($obj, 'fred')); }
public function testPassesCorrectEmailParameters() { $email = Mockery::mock('Skovachev\\Notifier\\Notifiers\\EmailNotifier')->makePartial(); Config::shouldReceive('get')->once()->with('notifier::email.enabled')->andReturn(true); Config::shouldReceive('get')->once()->with('notifier::views_folder')->andReturn('viewsFolder'); Config::shouldReceive('get')->once()->with('notifier::email.from_email')->andReturn('fromEmail'); Config::shouldReceive('get')->once()->with('notifier::email.cc_email')->andReturn('ccEmail'); Config::shouldReceive('get')->once()->with('notifier::email.bcc_email')->andReturn('bccEmail'); Config::shouldReceive('get')->once()->with('notifier::email.getter_email')->andReturn(function ($user) { return 'getterEmail'; }); Config::shouldReceive('get')->once()->with('notifier::email.getter_name')->andReturn(function ($user) { return 'userName'; }); $destination = array('email' => 'getterEmail', 'name' => 'userName', 'subject' => null, 'from_email' => 'fromEmail', 'cc_email' => 'ccEmail', 'bcc_email' => 'bccEmail'); $email->shouldReceive('sendNotification')->once()->with($destination, 'viewsFolder.email.fooView', array('foo' => 'bar', 'user' => 'fooUser')); $email->notify('fooUser', 'fooView', array('foo' => 'bar')); }
public function testSendSMSNotification() { $twilioClient = new stdClass(); $twilioClient->account = new stdClass(); $messageService = Mockery::mock('stdClass'); $twilioClient->account->sms_messages = $messageService; $messageService->shouldReceive('create')->once()->with('1234', 'fooUser', 'renderedContent'); $viewContent = Mockery::mock('stdClass'); $viewContent->shouldReceive('render')->once()->andReturn('renderedContent'); $sms = new \Skovachev\Notifier\Notifiers\SMSNotifier($twilioClient); Config::shouldReceive('get')->once()->with('notifier::sms.enabled')->andReturn(true); Config::shouldReceive('get')->once()->with('notifier::sms.getter_phone')->andReturn(function ($user) { return $user; }); Config::shouldReceive('get')->once()->with('notifier::sms.twilio.phone_number')->andReturn('1234'); Config::shouldReceive('get')->once()->with('notifier::views_folder')->andReturn('foobar'); View::shouldReceive('make')->once()->with('foobar.sms.fooView', array('foo' => 'bar', 'user' => 'fooUser'))->andReturn($viewContent); $sms->notify('fooUser', 'fooView', array('foo' => 'bar')); }
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()); }
/** * @test */ public function it_should_transform() { /** * * Set * */ $husband = m::mock('Husband')->makePartial(); /** * * Expectation * */ $husband->shouldReceive('load->toArray')->once()->andReturn('mock'); Config::clearResolvedInstance('config'); Config::shouldReceive('get')->with('/larasearch::paths\\..*/')->once(); /** * * Assertion * */ $transformed = $husband->transform(true); $this->assertEquals('mock', $transformed); }