Skip to content

Instantly share code, notes, and snippets.

@kbirmhrjn
Created January 6, 2014 07:55
Show Gist options
  • Save kbirmhrjn/8279608 to your computer and use it in GitHub Desktop.
Save kbirmhrjn/8279608 to your computer and use it in GitHub Desktop.
<?php
class MatchesControllerTest extends TestCase
{
protected $user;
protected $profile;
public function setUp()
{
parent::setUp();
DB::beginTransaction();
}
public function tearDown()
{
DB::rollBack();
}
public function authUser()
{
$this->user = User::first();
$this->be($this->user);
}
public function test_matches_create_user_profile()
{
$this->authUser();
$this->databaseTableSetUpForTesting();
$response = $this->call('GET','/matches');
$this->assertViewHas('searchMatches');
$searchMatches = $response->original->getData()['searchMatches'];
$this->assertInstanceOf('StdClass', $searchMatches);
}
protected function databaseTableSetUpForTesting()
{
$band = new Band($this->bandData());
$this->user->bands()->save($band);
$this->profile = $band;
$this->associateMatch();
}
public function bandData()
{
return [
'tab' => 'about',
'alias' => 'Match_band_test_123',
'genres' => 1,
'desired_instruments' => 1,
'bio' => 'String for bio',
];
}
public function associateMatch()
{
$this->matchIds = [];
foreach ( range(1, 10 ) as $index)
{
$matchableProfileId = Band::orderBy(DB::raw('RAND()'))->first()->id;
$model = Match::create([
'date_added' => Carbon\Carbon::now(),
'status' => 'new',
'profile_type' => 'band',
'profile_id' => $this->profile->id,
'match_profile_type' => 'band',
'match_profile_id' => $matchableProfileId
]);
$this->matchIds[] = $model->id;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment