Skip to content

Commit

Permalink
feat: reactivate unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
darthsoup committed Jan 23, 2021
1 parent 29fe3f6 commit d7bb096
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
composer.lock
.DS_Store
.idea
.phpunit.result.cache
9 changes: 7 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/Unit</directory>
<testsuite name="Test Suite">
<directory suffix=".php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>
28 changes: 7 additions & 21 deletions tests/Unit/Compilers/TemplateCompilerTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

namespace Dogado\Laroute\Compilers;
namespace Dogado\Tests\Laroute\Unit\Compilers;

use Mockery;
use Dogado\Laroute\Compilers\TemplateCompiler;
use Dogado\Laroute\Compilers\CompilerInterface;
use Orchestra\Testbench\TestCase;

class TemplateCompilerTest extends \PhpUnit\Framework\TestCase
class TemplateCompilerTest extends TestCase
{
protected $compiler;

public function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -17,10 +19,7 @@ public function setUp()

public function testItIsOfTheCorrectInterface()
{
$this->assertInstanceOf(
'Dogado\Laroute\Compilers\CompilerInterface',
$this->compiler
);
$this->assertInstanceOf(CompilerInterface::class, $this->compiler);
}

public function testItCanCompileAString()
Expand All @@ -31,17 +30,4 @@ public function testItCanCompileAString()

$this->assertSame($expected, $this->compiler->compile($template, $data));
}

public function tearDown()
{
Mockery::close();
}

protected function mock($class)
{
$mock = Mockery::mock($class);
$this->app->instance($class, $mock);

return $mock;
}
}
33 changes: 14 additions & 19 deletions tests/Unit/Generators/TemplateGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
<?php

namespace Dogado\Laroute\Generators;
namespace Dogado\Tests\Laroute\Unit\Generators;

use Mockery;
use Dogado\Laroute\Compilers\TemplateCompiler;
use Dogado\Laroute\Generators\GeneratorInterface;
use Dogado\Laroute\Generators\TemplateGenerator;
use Illuminate\Filesystem\Filesystem;
use Mockery as m;
use Orchestra\Testbench\TestCase;

class TemplateGeneratorTest extends \PhpUnit\Framework\TestCase
class TemplateGeneratorTest extends TestCase
{
protected $compiler;

protected $filesystem;

protected $generator;

public function setUp()
protected function setUp(): void
{
parent::setUp();

$this->compiler = $this->mock('Dogado\Laroute\Compilers\CompilerInterface');
$this->filesystem = $this->mock('Illuminate\Filesystem\Filesystem');
$this->compiler = m::mock(TemplateCompiler::class);
$this->filesystem = m::mock(Filesystem::class);

$this->generator = new TemplateGenerator($this->compiler, $this->filesystem);
}

public function testItIsOfTheCorrectInterface()
{
$this->assertInstanceOf(
'Dogado\Laroute\Generators\GeneratorInterface',
$this->generator
);
$this->assertInstanceOf(GeneratorInterface::class, $this->generator);
}

public function testItWillCompileAndSaveATemplate()
Expand Down Expand Up @@ -63,15 +65,8 @@ public function testItWillCompileAndSaveATemplate()
$this->assertSame($actual, $filePath);
}

public function tearDown()
public function tearDown(): void
{
Mockery::close();
}

protected function mock($class, $app = [])
{
$mock = Mockery::mock($class, $app);

return $mock;
m::close();
}
}
62 changes: 34 additions & 28 deletions tests/Unit/Routes/CollectionTest.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
<?php

namespace Dogado\Laroute\Routes;
namespace Dogado\Tests\Laroute\Unit\Routes;

use Mockery;
use Dogado\Laroute\Exceptions\ZeroRoutesException;
use Dogado\Laroute\Routes\Collection;
use Illuminate\Routing\Route;
use Illuminate\Routing\RouteCollection;
use Mockery as m;
use Orchestra\Testbench\TestCase;

class CollectionTest extends \PhpUnit\Framework\TestCase
class CollectionTest extends TestCase
{
protected $routeCollection;

protected $routes;
protected $collection;

public function setUp()
protected function setUp(): void
{
parent::setUp();

$this->routeCollection = $this->mock('Illuminate\Routing\RouteCollection');
$this->routes = $this->createInstance();
$this->routeCollection = m::mock(RouteCollection::class);
}

protected function createInstance()
public function testFailOnEmptyRoutes()
{
return; // Life is too short.
$this->routeCollection
->shouldReceive('count')
->once()
->andReturn(1)
->shouldReceive('getIterator')
->once()
->andReturn(['Huh?']);

return new Collection($this->routeCollection);
$this->expectException(ZeroRoutesException::class);
$this->routeCollection->shouldReceive('count')->once()->andReturn(0);
new Collection($this->routeCollection, 'all');
}

public function testIFailedAtTestingACollection()
{
$this->assertTrue(true);
$route = m::mock(Route::class);
$route->shouldReceive('domain')->once()->andReturn(null);
$route->shouldReceive('getDomain')->once()->andReturn(null);
$route->shouldReceive('methods')->twice()->andReturn(['GET']);
$route->shouldReceive('uri')->twice()->andReturn('/');
$route->shouldReceive('getName')->twice()->andReturn(0);
$route->shouldReceive('getAction')->twice()->andReturn([]);

$routeCollection = new RouteCollection();
$routeCollection->add($route);

$collection = new Collection($routeCollection, 'all');
$entry = $collection->first();
$this->assertArrayHasKey('host', $entry);
$this->assertArrayHasKey('methods', $entry);
$this->assertArrayHasKey('uri', $entry);
$this->assertArrayHasKey('name', $entry);
}

public function tearDown()
public function tearDown(): void
{
Mockery::close();
}

protected function mock($class, $app = [])
{
$mock = Mockery::mock($class, $app);

return $mock;
m::close();
}
}

0 comments on commit d7bb096

Please sign in to comment.