Skip to content

Commit

Permalink
modernized test suite
Browse files Browse the repository at this point in the history
now using PSR-4 autoloading
  • Loading branch information
frasmage committed Oct 12, 2020
1 parent 5ad8cea commit 508af5d
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 30 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"php-coveralls/php-coveralls": "^2.1"
},
"autoload-dev":{
"classmap": ["tests/"]
"psr-4": {
"Plank\\Metable\\Tests\\" : "tests/"
}
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
31 changes: 16 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
Expand All @@ -8,18 +9,18 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/integration/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
<ini name="display_errors" value="true"/>
</php>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/Integration/</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="true"/>
</php>
</phpunit>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Plank\Metable\Tests\Integration\DataType;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Plank\Metable\DataType\ArrayHandler;
Expand All @@ -14,6 +16,10 @@
use Plank\Metable\DataType\ObjectHandler;
use Plank\Metable\DataType\SerializableHandler;
use Plank\Metable\DataType\StringHandler;
use Plank\Metable\Tests\Mocks\SampleMetable;
use Plank\Metable\Tests\Mocks\SampleSerializable;
use Plank\Metable\Tests\TestCase;
use stdClass;

class HandlerTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

namespace Plank\Metable\Tests\Integration\DataType;

use Illuminate\Database\Eloquent\Collection;
use Plank\Metable\DataType\ModelCollectionHandler;
use Plank\Metable\Tests\Mocks\SampleMetable;
use Plank\Metable\Tests\TestCase;

class ModelCollectionHandlerTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

namespace Plank\Metable\Tests\Integration\DataType;

use Plank\Metable\DataType\ModelHandler;
use Plank\Metable\Tests\Mocks\SampleMetable;
use Plank\Metable\Tests\TestCase;

class ModelHandlerTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Plank\Metable\Tests\Integration\DataType;

use Plank\Metable\DataType\HandlerInterface;
use Plank\Metable\DataType\Registry;
use Plank\Metable\Exceptions\DataTypeException;
use Plank\Metable\Tests\TestCase;

class RegistryTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace Plank\Metable\Tests\Integration;

use Illuminate\Database\Eloquent\Relations\MorphTo;
use Plank\Metable\Meta;
use Plank\Metable\Tests\TestCase;

class MetaTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php

namespace Plank\Metable\Tests\Integration;

use Illuminate\Database\Eloquent\Collection;
use Plank\Metable\Meta;
use Plank\Metable\Tests\Mocks\SampleMetable;
use Plank\Metable\Tests\TestCase;
use ReflectionClass;

class MetableTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

use Illuminate\Support\Facades\DB;
namespace Plank\Metable\Tests\Integration;

use Plank\Metable\Meta;
use Plank\Metable\Tests\Mocks\SampleMetable;
use Plank\Metable\Tests\Mocks\SampleMorph;
use Plank\Metable\Tests\TestCase;

class MorphTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Plank\Metable\Tests\Mocks;

use Illuminate\Database\Eloquent\Model;
use Plank\Metable\Metable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Plank\Metable\Tests\Mocks;

use Plank\Metable\Metable;

class SampleMorph extends SampleMetable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace Plank\Metable\Tests\Mocks;

use Serializable;

class SampleSerializable implements Serializable
{
public $data;
Expand Down
19 changes: 11 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Plank\Metable\Tests;

use Orchestra\Testbench\TestCase as BaseTestCase;
use Plank\Metable\MetableServiceProvider;

Expand All @@ -8,7 +10,7 @@ class TestCase extends BaseTestCase
public function setUp(): void
{
parent::setUp();
$this->withFactories(__DIR__ . '/_data/factories');
$this->withFactories(__DIR__ . '/factories');
}

protected function getPackageProviders($app)
Expand Down Expand Up @@ -67,13 +69,14 @@ protected function getPrivateMethod($class, $method_name)

protected function useDatabase()
{
$artisan = $this->app->make('Illuminate\Contracts\Console\Kernel');
$database = $this->app['config']->get('database.default');
$this->app->useDatabasePath(realpath(__DIR__) . '/..');
$this->loadMigrationsFrom(__DIR__ . '/_migrations');
//Remigrate all database tables
$artisan->call('migrate:refresh', [
'--database' => $database,
]);
$this->loadMigrationsFrom(
[
'--path' => [
dirname(__DIR__) . '/migrations',
__DIR__ . '/migrations'
]
]
);
}
}
5 changes: 0 additions & 5 deletions tests/_data/factories/MetaFactory.php

This file was deleted.

7 changes: 7 additions & 0 deletions tests/factories/MetaFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Plank\Metable\Meta;

$factory->define(Meta::class, function (Faker\Generator $faker) {
return [];
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Plank\Metable\Tests\Mocks\SampleMetable;

$factory->define(SampleMetable::class, function (Faker\Generator $faker) {
return [];
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Plank\Metable\Tests\Mocks\SampleMorph;

$factory->define(SampleMorph::class, function (Faker\Generator $faker) {
return [];
});

0 comments on commit 508af5d

Please sign in to comment.