Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AydinHassan committed Jul 7, 2016
1 parent e57e761 commit 908025d
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 12 deletions.
12 changes: 12 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true">
<testsuite name="Workshop Manager Test Suite">
<directory>./test</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
136 changes: 124 additions & 12 deletions test/Repository/WorkshopRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace PhpSchool\WorkshopManagerTest\Repository;

use Composer\Json\JsonFile;
use PhpSchool\WorkshopManager\Entity\Workshop;
use PhpSchool\WorkshopManager\Exception\WorkshopNotFoundException;
use PhpSchool\WorkshopManager\Repository\InstalledWorkshopRepository;
use PhpSchool\WorkshopManager\Repository\WorkshopRepository;
use PHPUnit_Framework_TestCase;

Expand All @@ -20,33 +22,118 @@ public function test1()

public function testGetByNameThrowsExceptionIfWorkshopNotExist()
{
$repo = new WorkshopRepository();
$json = $this->createMock(JsonFile::class);
$json
->expects($this->once())
->method('read')
->will(
$this->returnValue(
[
'workshops' => []
]
)
);

$repo = new InstalledWorkshopRepository($json);
$this->expectException(WorkshopNotFoundException::class);
$repo->getByName('nope');
}

public function testGetByName()
{
$workshop = new Workshop('workshop', 'workshop', 'aydin', 'repo', 'workshop');
$repo = new WorkshopRepository([$workshop]);
$this->assertEquals($workshop, $repo->getByName('workshop'));
$json = $this->createMock(JsonFile::class);
$json
->expects($this->once())
->method('read')
->will($this->returnValue(
[
'workshops' => [
[
'name' => 'workshop',
'display_name' => 'workshop',
'owner' => 'aydin',
'repo' => 'repo',
'description' => 'workshop'
]
]
]
));

$repo = new InstalledWorkshopRepository($json);
$workshop = $repo->getByName('workshop');
$this->assertInstanceOf(Workshop::class, $workshop);
$this->assertEquals('workshop', $workshop->getName());
$this->assertEquals('workshop', $workshop->getDisplayName());
$this->assertEquals('aydin', $workshop->getOwner());
$this->assertEquals('repo', $workshop->getRepo());
$this->assertEquals('workshop', $workshop->getDescription());
}

public function testHasWorkshop()
{
$workshop = new Workshop('workshop', 'workshop', 'aydin', 'repo', 'workshop');
$repo = new WorkshopRepository([$workshop]);
$json = $this->createMock(JsonFile::class);
$json
->expects($this->once())
->method('read')
->will(
$this->returnValue(
[
'workshops' => [
[
'name' => 'workshop',
'display_name' => 'workshop',
'owner' => 'aydin',
'repo' => 'repo',
'description' => 'workshop'
]
]
]
)
);

$repo = new InstalledWorkshopRepository($json);
$this->assertTrue($repo->hasWorkshop('workshop'));


$repo = new WorkshopRepository();
$json = $this->createMock(JsonFile::class);
$json
->expects($this->once())
->method('read')
->will(
$this->returnValue(
[
'workshops' => []
]
)
);

$repo = new InstalledWorkshopRepository($json);
$this->assertFalse($repo->hasWorkshop('workshop'));
}

public function testFind()
{
$workshop = new Workshop('workshop', 'learn-you-php', 'aydin', 'repo', 'workshop');
$repo = new WorkshopRepository([$workshop]);
$json = $this->createMock(JsonFile::class);
$json
->expects($this->once())
->method('read')
->will(
$this->returnValue(
[
'workshops' => [
[
'name' => 'workshop',
'display_name' => 'learn-you-php',
'owner' => 'aydin',
'repo' => 'repo',
'description' => 'workshop'
]
]
]
)
);

$repo = new InstalledWorkshopRepository($json);

$this->assertCount(1, $repo->find('workshop'));
$this->assertCount(1, $repo->find('worksh'));
Expand All @@ -59,9 +146,34 @@ public function testFind()

public function testFindWithMultipleWorkshops()
{
$workshop1 = new Workshop('learnyouphp', 'Learn you PHP', 'aydin', 'repo', 'A workshop');
$workshop2 = new Workshop('php7', 'Learn PHP7', 'aydin', 'repo', 'A workshop');
$repo = new WorkshopRepository([$workshop1, $workshop2]);
$json = $this->createMock(JsonFile::class);
$json
->expects($this->once())
->method('read')
->will(
$this->returnValue(
[
'workshops' => [
[
'name' => 'learnyouphp',
'display_name' => 'Learn you PHP',
'owner' => 'aydin',
'repo' => 'repo',
'description' => 'A workshop'
],
[
'name' => 'php7',
'display_name' => 'Learn PHP7',
'owner' => 'aydin',
'repo' => 'repo',
'description' => 'A workshop'
]
]
]
)
);

$repo = new InstalledWorkshopRepository($json);

$this->assertCount(2, $repo->find('learn'));
$this->assertCount(2, $repo->find('php'));
Expand Down

0 comments on commit 908025d

Please sign in to comment.