Skip to content

Commit

Permalink
modify tests to use 5.4 features
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Jan 29, 2017
1 parent e4d4f9b commit dcd7d9a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
12 changes: 6 additions & 6 deletions tests/TeamworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function testCanInviteToTeam()
->with( m::type(TeamInvite::class) )->andReturn();
\Teamwork::inviteToTeam( $email, $team->getKey(), array($callback,'callback') );

$this->seeInDatabase(config('teamwork.team_invites_table'),[
$this->assertDatabaseHas(config('teamwork.team_invites_table'),[
'email' => 'asd@fake.com',
'user_id' => $this->user->getKey(),
'team_id' => $team->getKey()
Expand All @@ -185,7 +185,7 @@ public function testCanInviteToTeamWithObject()
->with( m::type(TeamInvite::class) )->andReturn();
\Teamwork::inviteToTeam( $email, $team, array($callback,'callback') );

$this->seeInDatabase(config('teamwork.team_invites_table'),[
$this->assertDatabaseHas(config('teamwork.team_invites_table'),[
'email' => 'asd@fake.com',
'user_id' => $this->user->getKey(),
'team_id' => $team->getKey()
Expand All @@ -204,7 +204,7 @@ public function testCanInviteToTeamWithArray()
->with( m::type(TeamInvite::class) )->andReturn();
\Teamwork::inviteToTeam( $email, $team->toArray(), array($callback,'callback') );

$this->seeInDatabase(config('teamwork.team_invites_table'),[
$this->assertDatabaseHas(config('teamwork.team_invites_table'),[
'email' => 'asd@fake.com',
'user_id' => $this->user->getKey(),
'team_id' => $team->getKey()
Expand All @@ -222,7 +222,7 @@ public function testCanInviteToTeamWithUser()
->with( m::type(TeamInvite::class) )->andReturn();
\Teamwork::inviteToTeam( $this->user, $team->toArray(), array($callback,'callback') );

$this->seeInDatabase(config('teamwork.team_invites_table'),[
$this->assertDatabaseHas(config('teamwork.team_invites_table'),[
'email' => 'asd@fake.com',
'user_id' => $this->user->getKey(),
'team_id' => $team->getKey()
Expand All @@ -242,7 +242,7 @@ public function testCanInviteToTeamWithNull()
->with( m::type(TeamInvite::class) )->andReturn();
\Teamwork::inviteToTeam( $email, null, array($callback,'callback') );

$this->seeInDatabase(config('teamwork.team_invites_table'),[
$this->assertDatabaseHas(config('teamwork.team_invites_table'),[
'email' => 'asd@fake.com',
'team_id' => $team->getKey()
]);
Expand All @@ -258,7 +258,7 @@ public function testCanInviteToTeamWithoutCallback()

\Teamwork::inviteToTeam( $email );

$this->seeInDatabase(config('teamwork.team_invites_table'),[
$this->assertDatabaseHas(config('teamwork.team_invites_table'),[
'email' => 'asd@fake.com',
'team_id' => $team->getKey()
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/UsedByTeamsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testScopeAutomaticallyAddsCurrentTeam()
$task->name = 'Buy milk';
$task->save();

$this->seeInDatabase('tasks', [
$this->assertDatabaseHas('tasks', [
'name' => 'Buy milk',
'team_id' => $this->user->currentTeam->getKey()
]);
Expand Down
17 changes: 13 additions & 4 deletions tests/UserHasTeamsTraitTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Event;
use Mpociot\Teamwork\TeamworkTeam;

class UserHasTeamsTraitTest extends Orchestra\Testbench\TestCase
Expand Down Expand Up @@ -119,7 +120,7 @@ public function testCanSetPivotDataOnAttachTeamMethod()

$this->user->attachTeam($team, $pivotData);

$this->seeInDatabase(config('teamwork.team_user_table'), [
$this->assertDatabaseHas(config('teamwork.team_user_table'), [
'user_id' => $this->user->getKey(),
'team_id' => $team->getKey(),
'pivot_set' => true
Expand Down Expand Up @@ -191,20 +192,28 @@ public function testDetachTeamResetsCurrentTeam()

public function testAttachTeamFiresEvent()
{
$this->expectsEvents(\Mpociot\Teamwork\Events\UserJoinedTeam::class);
$this->doesntExpectEvents(\Mpociot\Teamwork\Events\UserLeftTeam::class);
Event::fake();

$team1 = TeamworkTeam::create(['name' => 'Test-Team 1']);
$this->user->attachTeam($team1);

Event::assertDispatched(\Mpociot\Teamwork\Events\UserJoinedTeam::class, function ($e) use ($team1) {
return $e->getTeamId() === $team1->id && $e->getUser()->id === $this->user->id;
});
Event::assertNotDispatched(\Mpociot\Teamwork\Events\UserLeftTeam::class);
}

public function testDetachTeamFiresEvent()
{
$this->expectsEvents(\Mpociot\Teamwork\Events\UserLeftTeam::class);
Event::fake();

$team1 = TeamworkTeam::create(['name' => 'Test-Team 1']);
$this->user->attachTeam($team1);
$this->user->detachTeam($team1);

Event::assertDispatched(\Mpociot\Teamwork\Events\UserLeftTeam::class, function ($e) use ($team1) {
return $e->getTeamId() === $team1->id && $e->getUser()->id === $this->user->id;
});
}

public function testCanAttachMultipleTeams()
Expand Down

0 comments on commit dcd7d9a

Please sign in to comment.