Skip to content

Commit

Permalink
Refactoring tests (#40)
Browse files Browse the repository at this point in the history
- assertNull instead of assertSame(null, $condition);
- assertArraySubset when comparing arrays;
- assertFileEquals when comparing files.
- upgrade PHPUnit version to ^4.8.35
- use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase
  • Loading branch information
carusogabriel authored and kylekatarnls committed Nov 26, 2017
1 parent a68f1b5 commit 6f15913
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"require-dev": {
"composer/composer": "^1.2",
"phpunit/phpunit": "^4.8 || ^5.7",
"phpunit/phpunit": "^4.8.35 || ^5.7",
"phpunit/php-code-coverage": "^2.2 || ^4.0 || ^5.2",
"codeclimate/php-test-reporter": "^0.4.0"
},
Expand Down
3 changes: 2 additions & 1 deletion tests/BladeDirectivesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Factory;
use Illuminate\View\FileViewFinder;
use PHPUnit\Framework\TestCase;

include_once __DIR__ . '/helpers.php';

Expand Down Expand Up @@ -284,7 +285,7 @@ public function getCurrentPackage()
/**
* @coversDefaultClass \Bkwld\LaravelPug\ServiceProvider
*/
class BladeDirectivesTest extends \PHPUnit_Framework_TestCase
class BladeDirectivesTest extends TestCase
{
/**
* @var LaravelTestApp
Expand Down
34 changes: 17 additions & 17 deletions tests/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Bkwld\LaravelPug\Install;
use Illuminate\Filesystem\Filesystem;
use PHPUnit\Framework\TestCase;
use Pug\Pug;

class Io
Expand Down Expand Up @@ -57,7 +58,7 @@ public function getIo()
/**
* @coversDefaultClass \Bkwld\LaravelPug\Install
*/
class InstallTest extends \PHPUnit_Framework_TestCase
class InstallTest extends TestCase
{
/**
* @covers ::getVersion
Expand All @@ -82,7 +83,7 @@ public function testPublishVendorLaravel4()

self::assertSame('artisan config:publish bkwld/laravel-pug', $argv);

self::assertSame([
self::assertArraySubset([
'app/config/app.php not found, please add Bkwld\LaravelPug\ServiceProvider::class, in it in your providers.',
'> php artisan config:publish bkwld/laravel-pug' . "\nOK",
], $io->getMessages());
Expand All @@ -99,17 +100,17 @@ public function testPublishVendorLaravel4()

$diff = '';
try {
self::assertSame(
file_get_contents('app/config/laravel-4-app-config.php'),
file_get_contents('app/config/app.php')
self::assertFileEquals(
'app/config/laravel-4-app-config.php',
'app/config/app.php'
);
} catch (\PHPUnit_Framework_ExpectationFailedException $exception) {
$diff = $exception->getComparisonFailure()->getDiff();
}

unlink('app/config/app.php');

self::assertSame([
self::assertArraySubset([
'Pug service provided added to your app.',
'> php artisan config:publish bkwld/laravel-pug' . "\nOK",
], $io->getMessages());
Expand All @@ -136,17 +137,17 @@ public function testPublishVendorLaravel4()

$diff = '';
try {
self::assertSame(
file_get_contents('app/config/missing-comma-config.php'),
file_get_contents('app/config/app.php')
self::assertFileEquals(
'app/config/missing-comma-config.php',
'app/config/app.php'
);
} catch (\PHPUnit_Framework_ExpectationFailedException $exception) {
$diff = $exception->getComparisonFailure()->getDiff();
}

unlink('app/config/app.php');

self::assertSame([
self::assertArraySubset([
'Pug service provided added to your app.',
'> php artisan config:publish bkwld/laravel-pug' . "\nOK",
], $io->getMessages());
Expand Down Expand Up @@ -190,7 +191,7 @@ public function testPublishVendorLaravel54()
str_replace('"', '', $argv)
);

self::assertSame([
self::assertArraySubset([
'config/app.php not found, please add Bkwld\LaravelPug\ServiceProvider::class, in it in your providers.',
'> php artisan vendor:publish --provider="Bkwld\LaravelPug\ServiceProvider"' . "\nOK",
], $io->getMessages());
Expand All @@ -207,17 +208,17 @@ public function testPublishVendorLaravel54()

$diff = '';
try {
self::assertSame(
file_get_contents('config/laravel-5-app-config.php'),
file_get_contents('config/app.php')
self::assertFileEquals(
'config/laravel-5-app-config.php',
'config/app.php'
);
} catch (\PHPUnit_Framework_ExpectationFailedException $exception) {
$diff = $exception->getComparisonFailure()->getDiff();
}

unlink('config/app.php');

self::assertSame([
self::assertArraySubset([
'Pug service provided added to your app.',
'> php artisan vendor:publish --provider="Bkwld\LaravelPug\ServiceProvider"' . "\nOK",
], $io->getMessages());
Expand Down Expand Up @@ -249,10 +250,9 @@ public function testPublishVendorLaravel54()
str_replace('"', '', $argv)
);

self::assertSame([
self::assertArraySubset([
"config/app.php does not contain 'providers' => [], " .
'please add a providers list with Bkwld\LaravelPug\ServiceProvider::class in it.',

'> php artisan vendor:publish --provider="Bkwld\LaravelPug\ServiceProvider"' .
"\nOK",
], $io->getMessages());
Expand Down
3 changes: 2 additions & 1 deletion tests/PugBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Bkwld\LaravelPug\PugBladeCompiler;
use Illuminate\Filesystem\Filesystem;
use PHPUnit\Framework\TestCase;
use Pug\Pug;

class PugBladeCompilerGetAndSetPath extends PugBladeCompiler
Expand All @@ -24,7 +25,7 @@ public function setPath($path)
/**
* @coversDefaultClass \Bkwld\LaravelPug\PugBladeCompiler
*/
class PugBladeCompilerTest extends \PHPUnit_Framework_TestCase
class PugBladeCompilerTest extends TestCase
{
/**
* @covers ::getOption
Expand Down
3 changes: 2 additions & 1 deletion tests/PugCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Bkwld\LaravelPug\PugCompiler;
use Illuminate\Filesystem\Filesystem;
use PHPUnit\Framework\TestCase;
use Pug\Pug;

class PugCompilerGetAndSetPath extends PugCompiler
Expand All @@ -24,7 +25,7 @@ public function setPath($path)
/**
* @coversDefaultClass \Bkwld\LaravelPug\PugCompiler
*/
class PugCompilerTest extends \PHPUnit_Framework_TestCase
class PugCompilerTest extends TestCase
{
/**
* @covers ::isExpired
Expand Down
21 changes: 11 additions & 10 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Facade;
use Illuminate\View\Engines\CompilerEngine;
use PHPUnit\Framework\TestCase;
use Pug\Assets;

include_once __DIR__ . '/helpers.php';
Expand Down Expand Up @@ -344,7 +345,7 @@ public function get($name)
/**
* @coversDefaultClass \Bkwld\LaravelPug\ServiceProvider
*/
class ServiceProviderTest extends \PHPUnit_Framework_TestCase
class ServiceProviderTest extends TestCase
{
/**
* @var LaravelTestApp
Expand Down Expand Up @@ -388,9 +389,9 @@ public function testVersion()
*/
public function testRegister()
{
self::assertSame(null, $this->app->getSingleton('laravel-pug.pug'));
self::assertSame(null, $this->app->getSingleton('Bkwld\LaravelPug\PugCompiler'));
self::assertSame(null, $this->app->getSingleton('Bkwld\LaravelPug\PugBladeCompiler'));
self::assertNull($this->app->getSingleton('laravel-pug.pug'));
self::assertNull($this->app->getSingleton('Bkwld\LaravelPug\PugCompiler'));
self::assertNull($this->app->getSingleton('Bkwld\LaravelPug\PugBladeCompiler'));

$this->provider->register();
/** @var \Pug\Pug $pug */
Expand Down Expand Up @@ -427,9 +428,9 @@ public function testRegisterLaravel5()
});
$provider = new Laravel5ServiceProvider($app);

self::assertSame(null, $app->getSingleton('laravel-pug.pug'));
self::assertSame(null, $app->getSingleton('Bkwld\LaravelPug\PugCompiler'));
self::assertSame(null, $app->getSingleton('Bkwld\LaravelPug\PugBladeCompiler'));
self::assertNull($app->getSingleton('laravel-pug.pug'));
self::assertNull($app->getSingleton('Bkwld\LaravelPug\PugCompiler'));
self::assertNull($app->getSingleton('Bkwld\LaravelPug\PugBladeCompiler'));

$provider->register();
/** @var \Pug\Pug $pug */
Expand Down Expand Up @@ -479,7 +480,7 @@ public function testGetConfig()
*/
public function testProvides()
{
self::assertSame([
self::assertArraySubset([
'Bkwld\LaravelPug\PugCompiler',
'Bkwld\LaravelPug\PugBladeCompiler',
'laravel-pug.pug',
Expand All @@ -502,7 +503,7 @@ public function testBoot()
$this->provider->register();
$this->provider->boot();

self::assertSame(
self::assertArraySubset(
["pug","pug.php","jade","jade.php","pug.blade","pug.blade.php","jade.blade","jade.blade.php"],
$view->getExtensions()
);
Expand All @@ -523,7 +524,7 @@ public function testBoot()
$provider->register();
$provider->boot();

self::assertSame(
self::assertArraySubset(
["pug","pug.php","jade","jade.php","pug.blade","pug.blade.php","jade.blade","jade.blade.php"],
$view->getExtensions()
);
Expand Down
3 changes: 2 additions & 1 deletion tests/UpdateCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Composer\Composer;
use Composer\IO\NullIO;
use Composer\Script\Event as ComposerEvent;
use PHPUnit\Framework\TestCase;

class CaptureIO extends NullIO
{
Expand All @@ -31,7 +32,7 @@ public function write($messages, $newline = true, $verbosity = self::NORMAL)
/**
* @coversDefaultClass \Bkwld\LaravelPug\UpdateCheck
*/
class UpdateCheckTest extends \PHPUnit_Framework_TestCase
class UpdateCheckTest extends TestCase
{
private static function assertComposerSettingsTouchIO($directory, $touched)
{
Expand Down

0 comments on commit 6f15913

Please sign in to comment.