php Way-Tests-Factory类(方法)实例源码

下面列出了php Way-Tests-Factory 类(方法)源码代码实例,从而了解它的用法。

作者:00dav0    项目:marcadores-minima   
public function test_validacion_exitosa_con_clave_foranea_lugar()
 {
     $padre = Factory::create('App\\Lugar');
     $lugar = Factory::attributesFor('App\\Lugar', ['lug_abreviatura' => 'asd', 'lug_nombre' => 'asd', 'lug_tipo' => 'pais', 'parent_lug_id' => $padre->lug_id]);
     $validator = Validator::make($lugar, $this->rules, $this->messages);
     $this->assertTrue($validator->passes(), 'Se esperaba que falle la validadicon.');
 }

作者:kcsamit    项目:laravelsnippet   
public function testGetMostViewed()
 {
     $user = Factory::create('User');
     $this->be($user);
     $snippets = array();
     $tag = Factory::create('Tag');
     // create 3 approved snippets
     for ($i = 0; $i < 3; $i++) {
         $snippets[] = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null));
     }
     $redis = App::make('redis');
     // add 10 hits in snippet[1]
     $redis->zIncrBy('hits', 10, $snippets[1]->id);
     // add 5 hits in snippet[2]
     $redis->zIncrBy('hits', 5, $snippets[2]->id);
     // add 1 hit in snippet[0]
     $redis->zIncrBy('hits', 1, $snippets[0]->id);
     // expected ranking:
     // 1. $snippets[1]
     // 2. $snippets[2]
     // 3. $snippets[0]
     $snippetRepo = new EloquentSnippetRepository(new Snippet(), $this->app->make('LaraSnipp\\Repo\\Tag\\TagRepositoryInterface'), $this->app->make('LaraSnipp\\Repo\\User\\UserRepositoryInterface'));
     $snippetsResult = $snippetRepo->getMostViewed();
     $this->assertEquals($snippets[1], $snippetsResult[0]);
 }

作者:kcsamit    项目:laravelsnippet   
public function testHomePageTopSnippetContributors()
 {
     // with 2 approved and 1 not yet approved snippet
     $user = Factory::create('User', array('active' => 1));
     $this->be($user);
     Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null));
     Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null));
     Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null));
     // with 1 not yet approved snippet
     $secondUser = Factory::create('User', array('active' => 1));
     $this->be($secondUser);
     Factory::create('Snippet', array('author_id' => $secondUser->id, 'approved' => 0, 'deleted_at' => null));
     // with 1 approved and 3 not yet approved snippets
     $thirdUser = Factory::create('User', array('active' => 1));
     $this->be($thirdUser);
     Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 1, 'deleted_at' => null));
     Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 0, 'deleted_at' => null));
     Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 0, 'deleted_at' => null));
     Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 0, 'deleted_at' => null));
     $response = $this->call('GET', '/');
     $view = $response->original;
     // only 2 is expected since we are only rendering contributors w/ approved snippets
     $this->assertEquals(count($view['topSnippetContributors']), 2);
     # rank 1 should be $user
     $this->assertEquals($view['topSnippetContributors'][0]->full_name, $user->full_name);
     $this->assertEquals($view['topSnippetContributors'][0]->snippets_count, 2);
     # rank 2 should be $thirdUser
     $this->assertEquals($view['topSnippetContributors'][1]->full_name, $thirdUser->full_name);
     $this->assertEquals($view['topSnippetContributors'][1]->snippets_count, 1);
 }

作者:soror    项目:aur   
public function testEdit()
 {
     $this->mock->shouldReceive('with')->with('role')->andReturn($this->mock);
     $this->mock->shouldReceive('findOrFail')->with(3)->once()->andReturn(Factory::make($this->factory, array('id' => 3)));
     $this->get($this->url . '/3/edit', 3);
     $this->assertViewHas(substr($this->var, 0, -1));
 }

作者:00dav0    项目:marcadores-minima   
public function test_validacion_exitosa_con_formato_de_url()
 {
     $clienteFake = factory(App\Cliente::class)->make();
     $cliente = Factory::attributesFor('App\\Cliente', ['clt_nombre' => $clienteFake->clt_nombre, 'clt_descripcion' => '', 'clt_dominio' => $clienteFake->clt_dominio]);
     $validator = Validator::make($cliente, ClienteRequest::$rules, ClienteRequest::$messages);
     $this->assertTrue($validator->passes(), 'Se esperaba que la validacion de url sea exitosa.');
 }

作者:00dav0    项目:marcadores-minima   
public function test_validacion_exitosa()
 {
     $equipo = factory(App\Equipo::class)->create();
     $fase = factory(App\Fase::class)->create();
     $penalizacion = Factory::attributesFor('App\\PenalizacionTorneo', ['eqp_id' => $equipo->eqp_id, 'fas_id' => $fase->fas_id, 'ptr_puntos' => 1, 'ptr_motivo' => 'asd']);
     $validator = Validator::make($penalizacion, $this->rules, $this->messages);
     $this->assertTrue($validator->passes(), 'Se esperaba que la validadicon sea exitosa.');
 }

作者:ryanrobertsnam    项目:giftertipster.co   
public function testGetAdminAddTypes()
 {
     Factory::create('Giftertipster\\Entity\\Eloquent\\AddType', ['label' => 'foobar']);
     Factory::create('Giftertipster\\Entity\\Eloquent\\AddType', ['label' => 'admin-foobar']);
     $response = $this->repo->getAdminAddTypes();
     assertThat($response[0], hasKeyValuePair('label', 'admin-foobar'));
     assertThat($response[0], hasKeyValuePair('id', 2));
 }

作者:ryanrobertsnam    项目:giftertipster.co   
public function testUpdateForProduct()
 {
     $product = Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $keyword_profile = Factory::make('Giftertipster\\Entity\\Eloquent\\KeywordProfile');
     $product->keywordProfile()->save($keyword_profile);
     $this->repo->updateForProduct(1, ['profile' => ['updated', 'profile']]);
     assertThat(KeywordProfile::find(1)->profile, identicalTo(['updated', 'profile']));
 }

作者:kcsamit    项目:laravelsnippet   
public function testInvalidLoginUsingWrongCredentials()
 {
     $user = Factory::create('User', array('password' => 'admin', 'active' => 1));
     $inputs = array('username' => $user->username, 'password' => 'wrong password');
     $crawler = $this->client->request('POST', route('auth.postLogin', $inputs));
     $this->assertRedirectedToRoute('auth.getLogin');
     $this->assertSessionHas('message', 'Wrong username or password');
 }

作者:kcsamit    项目:laravelsnippet   
public function testGetMySnippetsRendersApprovedAndNotYetApprovedSnippets()
 {
     $user = Factory::create('User');
     $this->be($user);
     $notYetApprovedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null));
     $approvedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null));
     $response = $this->call('GET', route('member.user.dashboard'));
     $view = $response->original;
     $this->assertEquals(count($view['my_snippets']), 2);
 }

作者:ryanrobertsnam    项目:giftertipster.co   
public function testFillableAndGuardedAttributes()
 {
     $product = Factory::make('Giftertipster\\Entity\\Eloquent\\RangeCronJob');
     assertThat($product['guarded'], hasItemInArray('id'));
     assertThat($product['guarded'], hasItemInArray('created_at'));
     assertThat($product['guarded'], hasItemInArray('updated_at'));
     assertThat($product['fillable'], hasItemInArray('job_name'));
     assertThat($product['fillable'], hasItemInArray('last_id_processed'));
     assertThat($product['fillable'], hasItemInArray('last_status'));
 }

作者:kcsamit    项目:laravelsnippet   
public function testGetShowRendersApprovedSnippets()
 {
     $user = Factory::create('User');
     $this->be($user);
     $snippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null));
     $response = $this->call('GET', route('snippet.getShow', $snippet->slug));
     $this->assertResponseOk();
     $view = $response->original;
     $this->assertEquals($view['snippet']->title, $snippet->title);
 }

作者:soror    项目:aur   
public function testUsesRoleReturnsPermissionsArray()
 {
     $mock = Mockery::mock('Sorora\\Aurp\\Models\\Role');
     $mock->shouldReceive('load')->with('permissions')->once();
     $permissions = array(Factory::make('Sorora\\Aurp\\Models\\' . $this->model, array('id' => 1, 'task' => 'Foo')), Factory::make('Sorora\\Aurp\\Models\\' . $this->model, array('id' => 5, 'task' => 'Bar')));
     $mock->shouldReceive('getAttribute')->once()->andReturn((object) $permissions);
     $item = new Permission();
     $permissions = $item->usesRole($mock);
     $this->assertEquals($permissions, array(1 => 'Foo', 5 => 'Bar'));
 }

作者:kcsamit    项目:laravelsnippet   
public function testGetShowOnlyRendersApprovedSnippets()
 {
     $user = Factory::create('User');
     $this->be($user);
     $notYetApprovedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null));
     $approvedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null));
     $response = $this->call('GET', route('snippet.getIndex'));
     $view = $response->original;
     $this->assertEquals(count($view['snippets']), 1);
     $this->assertEquals($approvedSnippet->title, $view['snippets'][0]->title);
 }

作者:ryanrobertsnam    项目:giftertipster.co   
public function testGetUnfulfilledRequestsReturnsFalseWhenAllRequestsAreFulfilled()
 {
     Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]);
     Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $seed_request1 = Factory::create('Giftertipster\\Entity\\Eloquent\\ProductDeleteRequest', ['user_id' => 1, 'product_id' => 1, 'is_fulfilled' => 1, 'delete_type' => 'delete']);
     $seed_request2 = Factory::create('Giftertipster\\Entity\\Eloquent\\ProductDeleteRequest', ['user_id' => 1, 'product_id' => 2, 'is_fulfilled' => 1, 'delete_type' => 'delete']);
     $repo = $this->app->make('Giftertipster\\Repository\\ProductDeleteRequest\\EloquentProductDeleteRequestRepository');
     $requests = $repo->getUnfulfilledRequests();
     assertThat($requests, identicalTo(false));
 }

作者:00dav0    项目:marcadores-minima   
public function test_validacion_exitosa()
 {
     Factory::create('App\\Lugar', ['lug_id' => 1]);
     Factory::create('App\\TipoTorneo', ['ttr_id' => 1]);
     Factory::create('App\\Equipo', ['eqp_id' => 1, 'lug_id' => 1]);
     Factory::create('App\\Jugador', ['jug_id' => 1, 'jug_nacionalidad' => 1]);
     Factory::create('App\\Torneo', ['tor_id' => 1, 'lug_id' => 1, 'ttr_id' => 1]);
     $plantillaTorneo = Factory::attributesFor('App\\PlantillaTorneo', ['plt_numero_camiseta' => 1, 'eqp_id' => 1, 'jug_id' => 1, 'tor_id' => 1]);
     $validator = Validator::make($plantillaTorneo, $this->rules, $this->messages);
     $this->assertTrue($validator->passes(), 'Se esperaba que la validadicon sea exitosa.');
 }

作者:smarce    项目:openstacki   
public function testGetTrustedSitesByRealm()
 {
     $realm = 'https://*.test.com';
     $service = $this->app[OpenIdServiceCatalog::TrustedSitesService];
     $user = Factory::create('auth\\User');
     $res = $service->addTrustedSite($user, $realm, IAuthService::AuthorizationResponse_AllowForever, $data = array('email', 'profile', 'address'));
     $this->assertTrue(!is_null($res));
     $sites = $service->getTrustedSites($user, 'https://www.dev.test.com', $data = array('email', 'address'));
     $this->assertTrue(is_array($sites));
     $this->assertTrue(count($sites) > 0);
 }

作者:00dav0    项目:marcadores-minima   
public function test_validacion_falla_por_campos_demasiado_cortos()
 {
     $tipoFase = Factory::attributesFor('App\\TipoFase', ['tfa_nombre' => 'as', 'tfa_descripcion' => 'as']);
     $validator = Validator::make($tipoFase, $this->rules, $this->messages);
     $this->assertFalse($validator->passes(), 'Se esperaba que falle la validadicon.');
     $this->assertTrue($validator->errors()->has('tfa_nombre'), 'Se esperaba que exista la clave tfa_nombre');
     $this->assertCount(1, $validator->errors()->get('tfa_nombre'), 'Se esperaba que exista 1 error en la clave tfa_nombre');
     $this->assertTrue($validator->errors()->has('tfa_descripcion'), 'Se esperaba que exista la clave tfa_descripcion');
     $this->assertCount(1, $validator->errors()->get('tfa_descripcion'), 'Se esperaba que exista 1 error en la clave tfa_descripcion');
     $this->assertCount(2, $validator->errors()->all(), 'Se esperaban 2 errores de validacion');
 }

作者:ryanrobertsnam    项目:giftertipster.co   
public function testCreateFailsIfIdeaAlreadyExistsAndReturnsFalseWithErrors()
 {
     Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]);
     $idea_repo = $this->app->make('Giftertipster\\Repository\\Idea\\EloquentIdeaRepository');
     $new_idea = 'blender';
     $response = $idea_repo->create(['user_id' => 1, 'description' => $new_idea, 'is_fulfilled' => 0]);
     $idea = $this->eloquent_idea->find(1);
     $response = $idea_repo->create(['user_id' => 1, 'description' => $new_idea, 'is_fulfilled' => 0]);
     $errors = $idea_repo->errors();
     assertThat($response, identicalTo(false));
     assertThat($errors->first(), equalTo('The description has already been taken.'));
 }

作者:kcsamit    项目:laravelsnippet   
public function testGetSnippets()
 {
     $user = Factory::create('User', array('active' => 1));
     $this->be($user);
     $notYetApprovedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null));
     $approvedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null));
     $response = $this->call('GET', route('user.getSnippets', $user->slug));
     $this->assertResponseOk();
     $view = $response->original;
     # should be 1 because only 1 submitted snippet of $user is approved
     $this->assertEquals(1, count($view['snippets']));
     $this->assertViewHas('user');
 }


问题


面经


文章

微信
公众号

扫码关注公众号