diff --git a/.circleci/config.yml b/.circleci/config.yml
index e728247..6a85f78 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -3,7 +3,7 @@ jobs:
build:
docker:
# specify the version you desire here
- - image: circleci/php:7.1-browsers
+ - image: circleci/php:7.2-browsers
working_directory: ~/repo
diff --git a/.gitignore b/.gitignore
index 57c3896..4bb0313 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,5 +3,7 @@ storage/
composer.lock
.idea
+publish/docker-compose/.env
tests/storage/
+.phpunit.result.cache
diff --git a/Makefile b/Makefile
index b9baa2c..0d07c01 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,5 @@
phpunit:
- @echo "Setting different namespace for Laravel tests"
- @php tests/Fake/Integration/Laravel/artisan app:name Laravel
- @mkdir vendor/laravel/lumen/config/
- @cp tests/Fake/database.php vendor/laravel/lumen/config/database.php
@echo "Running phpunit..."
@vendor/bin/phpunit
@echo "Cleanup..."
@rm -rf ./tests/storage
- @rm -rf vendor/laravel/lumen/config
diff --git a/composer.json b/composer.json
index 909c59f..d472b8f 100644
--- a/composer.json
+++ b/composer.json
@@ -24,18 +24,17 @@
"vendor/laravel/lumen/tests/"
],
"BaseTree\\Tests\\": "tests/",
- "Laravel\\": "vendor/laravel/laravel/app/",
- "App\\": "vendor/laravel/lumen/app/"
+ "App\\": "vendor/laravel/laravel/app/"
}
},
"require": {
"barryvdh/laravel-ide-helper": "^2.4",
- "illuminate/contracts": "^5.0",
- "illuminate/console": "^5.0",
- "illuminate/container": "^5.0",
- "illuminate/http": "^5.0",
- "illuminate/support": "^5.0",
- "yajra/laravel-datatables-oracle": ">8"
+ "illuminate/contracts": "^6.0",
+ "illuminate/console": "^6.0",
+ "illuminate/container": "^6.0",
+ "illuminate/http": "^6.0",
+ "illuminate/support": "^6.0",
+ "yajra/laravel-datatables-oracle": ">9"
},
"require-dev": {
"fzaninotto/faker": "^1.4",
@@ -43,9 +42,8 @@
"filp/whoops": "^2.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
- "phpunit/phpunit": "^7.0",
- "laravel/laravel": "5.7.*",
- "laravel/lumen": "5.7.*"
+ "phpunit/phpunit": "^8.0",
+ "laravel/laravel": "^6.0"
},
"extra": {
"laravel": {
diff --git a/phpunit.xml b/phpunit.xml
index 4ec0c9f..5c80c86 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -15,9 +15,6 @@
./tests/Integration/Laravel
-
- ./tests/Integration/Lumen
-
diff --git a/publish/docker-compose/docker-compose.yml b/publish/docker-compose/docker-compose.yml
index 42563e6..3cd4bcb 100644
--- a/publish/docker-compose/docker-compose.yml
+++ b/publish/docker-compose/docker-compose.yml
@@ -7,8 +7,6 @@ services:
build:
context: docker
dockerfile: local.Dockerfile
- links:
- - mariadb
volumes:
- .:${CONTAINER_ROOT}
- ./docker/${APP_ENV}/conf/supervisord.conf:/etc/supervisord.conf
@@ -27,15 +25,15 @@ services:
- PGID=${DOCKER_HOST_GID}
# Services
- mariadb:
- image: mariadb:10.3
- hostname: mariadb
- container_name: mariadb
- volumes:
- - ${DATABASE_LOCAL_STORAGE}:/var/lib/mysql:rw
- environment:
- - MYSQL_DATABASE=${DB_DATABASE}
- - MYSQL_USER=${DB_USERNAME}
- - MYSQL_PASSWORD=${DB_PASSWORD}
- - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
+# mariadb:
+# image: mariadb:10.3
+# hostname: mariadb
+# container_name: mariadb
+# volumes:
+# - ${DATABASE_LOCAL_STORAGE}:/var/lib/mysql:rw
+# environment:
+# - MYSQL_DATABASE=${DB_DATABASE}
+# - MYSQL_USER=${DB_USERNAME}
+# - MYSQL_PASSWORD=${DB_PASSWORD}
+# - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
diff --git a/publish/docker-compose/docker/local.Dockerfile b/publish/docker-compose/docker/local.Dockerfile
index 3b5cfa8..fee0763 100644
--- a/publish/docker-compose/docker/local.Dockerfile
+++ b/publish/docker-compose/docker/local.Dockerfile
@@ -1,16 +1,16 @@
FROM php:7.2.3-fpm-stretch
-MAINTAINER Jimmy
+MAINTAINER Jimmy
### NGINX
-ARG NGINX_VERSION=1.10.3-1+deb9u1
-ARG YARN_VERSION=1.10.1-1
+ARG NGINX_VERSION=1.10.3-1+deb9u3
+ARG YARN_VERSION=1.19.1-1
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils gnupg2 apt-transport-https
### Required repositories
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
-RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
+RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
### NGINX
RUN addgroup --system nginx \
diff --git a/readme.md b/readme.md
index 4671a95..a9bd0b0 100644
--- a/readme.md
+++ b/readme.md
@@ -1,5 +1,12 @@
[![CircleCI](https://circleci.com/gh/KenoKokoro/laravel-basetree.svg?style=svg)](https://circleci.com/gh/KenoKokoro/laravel-basetree)
+## Support
+|Laravel | Version |
+|:------------|--------------:|
+|< 5.6 | 1.* |
+|5.6,5.7,5.8 | 2.* |
+|6.x | 3.* |
+
## Installation
`composer require kenokokoro/laravel-basetree`
diff --git a/src/Console/ApplicationNamespace.php b/src/Console/ApplicationNamespace.php
new file mode 100644
index 0000000..a745d23
--- /dev/null
+++ b/src/Console/ApplicationNamespace.php
@@ -0,0 +1,264 @@
+files = $files;
+ $this->composer = $composer;
+ }
+
+ /**
+ * Execute the console command.
+ * @return void
+ */
+ public function handle()
+ {
+ $this->currentRoot = trim($this->laravel->getNamespace(), '\\');
+ $this->setAppDirectoryNamespace();
+ $this->setBootstrapNamespaces();
+ $this->setConfigNamespaces();
+ $this->setComposerNamespace();
+ $this->setDatabaseFactoryNamespaces();
+ $this->info('Application namespace set!');
+ $this->composer->dumpAutoloads();
+ $this->call('optimize:clear');
+ }
+
+ /**
+ * Set the namespace on the files in the app directory.
+ * @return void
+ */
+ protected function setAppDirectoryNamespace()
+ {
+ $files = Finder::create()
+ ->in($this->laravel['path'])
+ ->contains($this->currentRoot)
+ ->name('*.php');
+ foreach ($files as $file) {
+ $this->replaceNamespace($file->getRealPath());
+ }
+ }
+
+ /**
+ * Replace the App namespace at the given path.
+ * @param string $path
+ * @return void
+ */
+ protected function replaceNamespace($path)
+ {
+ $search = [
+ 'namespace ' . $this->currentRoot . ';',
+ $this->currentRoot . '\\',
+ ];
+ $replace = [
+ 'namespace ' . $this->argument('name') . ';',
+ $this->argument('name') . '\\',
+ ];
+ $this->replaceIn($path, $search, $replace);
+ }
+
+ /**
+ * Set the bootstrap namespaces.
+ * @return void
+ */
+ protected function setBootstrapNamespaces()
+ {
+ $search = [
+ $this->currentRoot . '\\Http',
+ $this->currentRoot . '\\Console',
+ $this->currentRoot . '\\Exceptions',
+ ];
+ $replace = [
+ $this->argument('name') . '\\Http',
+ $this->argument('name') . '\\Console',
+ $this->argument('name') . '\\Exceptions',
+ ];
+ $this->replaceIn($this->getBootstrapPath(), $search, $replace);
+ }
+
+ /**
+ * Set the namespace in the appropriate configuration files.
+ * @return void
+ */
+ protected function setConfigNamespaces(): void
+ {
+ $this->setAppConfigNamespaces();
+ $this->setAuthConfigNamespace();
+ $this->setServicesConfigNamespace();
+ }
+
+ /**
+ * Set the application provider namespaces.
+ * @return void
+ */
+ protected function setAppConfigNamespaces(): void
+ {
+ $search = [
+ $this->currentRoot . '\\Providers',
+ $this->currentRoot . '\\Http\\Controllers\\',
+ ];
+ $replace = [
+ $this->argument('name') . '\\Providers',
+ $this->argument('name') . '\\Http\\Controllers\\',
+ ];
+ $this->replaceIn($this->getConfigPath('app'), $search, $replace);
+ }
+
+ /**
+ * Set the authentication User namespace.
+ * @return void
+ */
+ protected function setAuthConfigNamespace(): void
+ {
+ $this->replaceIn(
+ $this->getConfigPath('auth'),
+ $this->currentRoot . '\\User',
+ $this->argument('name') . '\\User'
+ );
+ }
+
+ /**
+ * Set the services User namespace.
+ * @return void
+ */
+ protected function setServicesConfigNamespace(): void
+ {
+ $this->replaceIn(
+ $this->getConfigPath('services'),
+ $this->currentRoot . '\\User',
+ $this->argument('name') . '\\User'
+ );
+ }
+
+ /**
+ * Set the PSR-4 namespace in the Composer file.
+ * @return void
+ */
+ protected function setComposerNamespace(): void
+ {
+ $this->replaceIn(
+ $this->getComposerPath(),
+ str_replace('\\', '\\\\', $this->currentRoot) . '\\\\',
+ str_replace('\\', '\\\\', $this->argument('name')) . '\\\\'
+ );
+ }
+
+ /**
+ * Set the namespace in database factory files.
+ * @return void
+ */
+ protected function setDatabaseFactoryNamespaces(): void
+ {
+ $files = Finder::create()
+ ->in(database_path('factories'))
+ ->contains($this->currentRoot)
+ ->name('*.php');
+ foreach ($files as $file) {
+ $this->replaceIn(
+ $file->getRealPath(),
+ $this->currentRoot, $this->argument('name')
+ );
+ }
+ }
+
+ /**
+ * Replace the given string in the given file.
+ * @param string $path
+ * @param string|array $search
+ * @param string|array $replace
+ * @return void
+ * @throws FileNotFoundException
+ */
+ protected function replaceIn($path, $search, $replace): void
+ {
+ if ($this->files->exists($path)) {
+ $this->files->put($path, str_replace($search, $replace, $this->files->get($path)));
+ }
+ }
+
+ /**
+ * Get the path to the bootstrap/app.php file.
+ * @return string
+ */
+ protected function getBootstrapPath(): string
+ {
+ return $this->laravel->bootstrapPath() . '/app.php';
+ }
+
+ /**
+ * Get the path to the Composer.json file.
+ * @return string
+ */
+ protected function getComposerPath(): string
+ {
+ return base_path('composer.json');
+ }
+
+ /**
+ * Get the path to the given configuration file.
+ * @param string $name
+ * @return string
+ */
+ protected function getConfigPath($name): string
+ {
+ return $this->laravel['path.config'] . '/' . $name . '.php';
+ }
+
+ /**
+ * Get the console command arguments.
+ * @return array
+ */
+ protected function getArguments()
+ {
+ return [
+ ['name', InputArgument::REQUIRED, 'The desired namespace'],
+ ];
+ }
+}
diff --git a/src/Console/Generators/BaseGenerator.php b/src/Console/Generators/BaseGenerator.php
index 52cbad0..cbbc057 100644
--- a/src/Console/Generators/BaseGenerator.php
+++ b/src/Console/Generators/BaseGenerator.php
@@ -6,13 +6,13 @@
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
+use Illuminate\Support\Arr;
use Symfony\Component\Console\Exception\InvalidArgumentException;
abstract class BaseGenerator extends Command
{
const OPTION_FOLDER = 'folder';
const OPTION_NAMESPACE = 'namespace';
- const OPTION_NAME = 'name';
const KEY_MODEL_NAMESPACE = 'model-namespace';
const KEY_MODEL_NAME = 'model-name';
@@ -47,7 +47,7 @@ public function handle()
protected function validateOptions()
{
- $options = array_except($this->options(),
+ $options = Arr::except($this->options(),
['help', 'quiet', 'verbose', 'version', 'ansi', 'no-ansi', 'no-interaction', 'env']);
foreach ($options as $key => $value) {
@@ -117,4 +117,4 @@ public function returnNamespace(string $namespace): string
abstract protected function extractModifiers();
abstract protected function go();
-}
\ No newline at end of file
+}
diff --git a/src/Console/Generators/ServiceProvider.php b/src/Console/Generators/ServiceProvider.php
index 706ab5f..6c5915e 100644
--- a/src/Console/Generators/ServiceProvider.php
+++ b/src/Console/Generators/ServiceProvider.php
@@ -4,6 +4,7 @@
namespace BaseTree\Console\Generators;
+use BaseTree\Console\ApplicationNamespace;
use BaseTree\Console\Generators\BLL\GenerateBll;
use BaseTree\Console\Generators\Controller\GenerateController;
use BaseTree\Console\Generators\DAL\GenerateDal;
@@ -15,9 +16,9 @@ class ServiceProvider extends LaravelServiceProvider
public function boot()
{
# Generators
- $this->commands([GenerateDal::class, GenerateBll::class, GenerateController::class]);
+ $this->commands([GenerateDal::class, GenerateBll::class, GenerateController::class, ApplicationNamespace::class]);
# Publisher
$this->commands([PublishBoilerplate::class]);
}
-}
\ No newline at end of file
+}
diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php
index 1a9a346..7ca619e 100644
--- a/src/Resources/BaseResource.php
+++ b/src/Resources/BaseResource.php
@@ -1,9 +1,7 @@
repository->create(array_only($attributes, $this->fillable));
+ $model = $this->repository->create(Arr::only($attributes, $this->fillable));
if ($this instanceof CreatedCallback) {
- $this->created($model, $attributes, array_except($attributes, $this->fillable) ?? []);
+ $this->created($model, $attributes, Arr::except($attributes, $this->fillable) ?? []);
}
/** @var EloquentModel $model */
@@ -129,13 +128,13 @@ public function updateEntity(BaseTreeModel $model, array $attributes)
}
}
- if ( ! empty($this->fillable)) {
- $attributes = array_except($attributes, $this->excludedOnUpdate);
- $updated = $this->repository->update($model, array_only($attributes, $this->fillable));
+ if (!empty($this->fillable)) {
+ $attributes = Arr::except($attributes, $this->excludedOnUpdate);
+ $updated = $this->repository->update($model, Arr::only($attributes, $this->fillable));
}
if ($this instanceof UpdatedCallback) {
- $this->updated($old, $updated ?? null, $attributes, array_except($attributes, $this->fillable) ?? []);
+ $this->updated($old, $updated ?? null, $attributes, Arr::except($attributes, $this->fillable) ?? []);
}
/** @var EloquentModel $model */
diff --git a/src/Testing/LumenDatabaseTestCase.php b/src/Testing/LumenDatabaseTestCase.php
deleted file mode 100644
index b7ab98d..0000000
--- a/src/Testing/LumenDatabaseTestCase.php
+++ /dev/null
@@ -1,33 +0,0 @@
-response->getContent(), true);
-
- if (is_null($decodedResponse) or $decodedResponse === false) {
- if ($this->response->exception) {
- throw $this->response->exception;
- } else {
- PHPUnit::fail('Invalid JSON was returned from the route.');
- }
- }
-
- return data_get($decodedResponse, $key);
- }
-}
\ No newline at end of file
diff --git a/tests/Fake/Integration/DatabaseSeeder.php b/tests/Fake/Integration/DatabaseSeeder.php
index b7c53cd..11ac246 100644
--- a/tests/Fake/Integration/DatabaseSeeder.php
+++ b/tests/Fake/Integration/DatabaseSeeder.php
@@ -4,6 +4,7 @@
namespace BaseTree\Tests\Fake\Integration;
+use App\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
@@ -12,10 +13,8 @@ class DatabaseSeeder extends Seeder
public function run(): void
{
- $class = \App\User::class;
-
if (static::$isLaravel === true) {
- $class = \Laravel\User::class;
+ $class = User::class;
}
create($class, 15);
diff --git a/tests/Fake/Integration/Laravel/artisan b/tests/Fake/Integration/Laravel/artisan
deleted file mode 100644
index 6db4534..0000000
--- a/tests/Fake/Integration/Laravel/artisan
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env php
-singleton(Kernel::class, ConsoleKernel::class);
-$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
-
-$status = $kernel->handle(
- $input = new Symfony\Component\Console\Input\ArgvInput,
- new Symfony\Component\Console\Output\ConsoleOutput
-);
-
-$kernel->terminate($input, $status);
-
-exit($status);
-
diff --git a/tests/Fake/Integration/Lumen/ConsoleKernel.php b/tests/Fake/Integration/Lumen/ConsoleKernel.php
deleted file mode 100644
index 1cac637..0000000
--- a/tests/Fake/Integration/Lumen/ConsoleKernel.php
+++ /dev/null
@@ -1,12 +0,0 @@
- env('DB_CONNECTION', 'mysql'),
-
- /*
- |--------------------------------------------------------------------------
- | Database Connections
- |--------------------------------------------------------------------------
- |
- | Here are each of the database connections setup for your application.
- | Of course, examples of configuring each database platform that is
- | supported by Laravel is shown below to make development simple.
- |
- |
- | All database work in Laravel is done through the PHP PDO facilities
- | so make sure you have the driver for your particular database of
- | choice installed on your machine before you begin development.
- |
- */
-
- 'connections' => [
- 'testing' => [
- 'driver' => 'sqlite',
- 'database' => ':memory:',
- 'prefix' => '',
- ],
-
- 'sqlite' => [
- 'driver' => 'sqlite',
- 'database' => env('DB_DATABASE', database_path('database.sqlite')),
- 'prefix' => '',
- ],
-
- 'mysql' => [
- 'driver' => 'mysql',
- 'host' => env('DB_HOST', '127.0.0.1'),
- 'port' => env('DB_PORT', '3306'),
- 'database' => env('DB_DATABASE', 'forge'),
- 'username' => env('DB_USERNAME', 'forge'),
- 'password' => env('DB_PASSWORD', ''),
- 'unix_socket' => env('DB_SOCKET', ''),
- 'charset' => 'utf8mb4',
- 'collation' => 'utf8mb4_unicode_ci',
- 'prefix' => '',
- 'strict' => true,
- 'engine' => null,
- ],
-
- 'pgsql' => [
- 'driver' => 'pgsql',
- 'host' => env('DB_HOST', '127.0.0.1'),
- 'port' => env('DB_PORT', '5432'),
- 'database' => env('DB_DATABASE', 'forge'),
- 'username' => env('DB_USERNAME', 'forge'),
- 'password' => env('DB_PASSWORD', ''),
- 'charset' => 'utf8',
- 'prefix' => '',
- 'schema' => 'public',
- 'sslmode' => 'prefer',
- ],
-
- 'sqlsrv' => [
- 'driver' => 'sqlsrv',
- 'host' => env('DB_HOST', 'localhost'),
- 'port' => env('DB_PORT', '1433'),
- 'database' => env('DB_DATABASE', 'forge'),
- 'username' => env('DB_USERNAME', 'forge'),
- 'password' => env('DB_PASSWORD', ''),
- 'charset' => 'utf8',
- 'prefix' => '',
- ],
-
- ],
-
- /*
- |--------------------------------------------------------------------------
- | Migration Repository Table
- |--------------------------------------------------------------------------
- |
- | This table keeps track of all the migrations that have already run for
- | your application. Using this information, we can determine which of
- | the migrations on disk haven't actually been run in the database.
- |
- */
-
- 'migrations' => 'migrations',
-
- /*
- |--------------------------------------------------------------------------
- | Redis Databases
- |--------------------------------------------------------------------------
- |
- | Redis is an open source, fast, and advanced key-value store that also
- | provides a richer set of commands than a typical key-value systems
- | such as APC or Memcached. Laravel makes it easy to dig right in.
- |
- */
-
- 'redis' => [
-
- 'client' => 'predis',
-
- 'default' => [
- 'host' => env('REDIS_HOST', '127.0.0.1'),
- 'password' => env('REDIS_PASSWORD', null),
- 'port' => env('REDIS_PORT', 6379),
- 'database' => env('REDIS_DB', 0),
- ],
-
- 'cache' => [
- 'host' => env('REDIS_HOST', '127.0.0.1'),
- 'password' => env('REDIS_PASSWORD', null),
- 'port' => env('REDIS_PORT', 6379),
- 'database' => env('REDIS_CACHE_DB', 1),
- ],
-
- ],
-
-];
-
diff --git a/tests/Integration/Laravel/API/RouteResponsesTest.php b/tests/Integration/Laravel/API/RouteResponsesTest.php
index d9f7cd0..67b9480 100644
--- a/tests/Integration/Laravel/API/RouteResponsesTest.php
+++ b/tests/Integration/Laravel/API/RouteResponsesTest.php
@@ -1,9 +1,7 @@
jsonGet('get-route-no-action');
$response->assertStatus(JsonResponse::HTTP_INTERNAL_SERVER_ERROR)->assertJsonStructure(['message']);
- $this->assertEquals('Class MissingController does not exist', $response->json('message'));
+ $this->assertEquals('Target class [MissingController] does not exist.', $response->json('message'));
}
}
\ No newline at end of file
diff --git a/tests/Integration/LaravelTestCase.php b/tests/Integration/LaravelTestCase.php
index c56a422..a4e3219 100644
--- a/tests/Integration/LaravelTestCase.php
+++ b/tests/Integration/LaravelTestCase.php
@@ -25,7 +25,7 @@ class LaravelTestCase extends LaravelDatabaseTestCase
*/
protected $request;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->request = $this->app->make(Request::class);
@@ -44,7 +44,7 @@ public function createApplication()
$app->make(Kernel::class)->bootstrap();
$app->singleton(ExceptionHandler::class, LaravelHandler::class);
- $app->singleton(\Illuminate\Contracts\Http\Kernel::class, \Laravel\Http\Kernel::class);
+ $app->singleton(\Illuminate\Contracts\Http\Kernel::class, \App\Http\Kernel::class);
$app->make(Hasher::class)->setRounds(4);
$app->register(RouteServiceProvider::class);
@@ -78,4 +78,4 @@ private function setDatabase(Application $application): void
'prefix' => '',
]);
}
-}
\ No newline at end of file
+}
diff --git a/tests/Integration/Lumen/API/RouteResponsesTest.php b/tests/Integration/Lumen/API/RouteResponsesTest.php
deleted file mode 100644
index b28937c..0000000
--- a/tests/Integration/Lumen/API/RouteResponsesTest.php
+++ /dev/null
@@ -1,32 +0,0 @@
-jsonGet('missing-route');
- $response->assertResponseStatus(JsonResponse::HTTP_NOT_FOUND);
- }
-
- /** @test */
- public function not_defined_method_for_valid_route_should_return_method_not_allowed_response(): void
- {
- $response = $this->jsonPost('get-route-no-action');
- $response->assertResponseStatus(JsonResponse::HTTP_METHOD_NOT_ALLOWED);
- }
-
- /** @test */
- public function any_internal_application_error_should_respond_with_internal_error_response(): void
- {
- $response = $this->jsonGet('get-route-no-action');
- $response->assertResponseStatus(JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
- }
-}
\ No newline at end of file
diff --git a/tests/Integration/Lumen/API/UsersControllerTest.php b/tests/Integration/Lumen/API/UsersControllerTest.php
deleted file mode 100644
index 69a8b7f..0000000
--- a/tests/Integration/Lumen/API/UsersControllerTest.php
+++ /dev/null
@@ -1,44 +0,0 @@
-jsonGet('users');
- $response->assertResponseStatus(JsonResponse::HTTP_OK);
-
- $this->assertCount(15, $response->jsonResponse('data'));
- }
-
- /** @test */
- public function it_should_return_paginated_results_if_requested(): void
- {
- $response = $this->jsonGet('users?paginate=1&perPage=4&page=2');
- $response->assertResponseStatus(JsonResponse::HTTP_OK);
-
- $data = $response->jsonResponse('data');
- $this->assertCount(4, $data['data']);
- $this->assertEquals(2, $data['current_page']);
- $this->assertEquals(5, $data['from']);
- $this->assertEquals(8, $data['to']);
- $this->assertEquals(15, $data['total']);
- }
-
- /** @test */
- public function it_should_return_data_tables_response_if_requested(): void
- {
- $response = $this->jsonGet('users?datatable=1');
- $response->assertResponseStatus(JsonResponse::HTTP_OK);
-
- $data = $response->jsonResponse('data');
- $this->assertCount(15, $data['data']);
- }
-}
\ No newline at end of file
diff --git a/tests/Integration/LumenTestCase.php b/tests/Integration/LumenTestCase.php
deleted file mode 100644
index 3169edb..0000000
--- a/tests/Integration/LumenTestCase.php
+++ /dev/null
@@ -1,107 +0,0 @@
-request = $this->app->make(Request::class);
- }
-
- /**
- * Boot the application the way we need it
- * @return Application
- */
- public function createApplication()
- {
- DatabaseSeeder::$isLaravel = false;
- $app = $this->buildApp();
-
- $app->bind(UserRepository::class, EloquentUser::class);
- $this->setDatabase();
- $this->setRoutes($app);
-
- return $app;
- }
-
- /**
- * Overwrite the default seeder class name
- * @return string
- */
- protected function getSeederClassName(): string
- {
- return DatabaseSeeder::class;
- }
-
- /**
- * Mock the app.php from Lumen's bootstrap file
- * @return Application
- */
- private function buildApp(): Application
- {
- try {
- (new Dotenv(__DIR__ . '/../'))->load();
- } catch (InvalidPathException $e) {
- //
- }
-
- $app = new Application(realpath(__DIR__ . '/../../vendor/laravel/lumen/'));
- $app->instance('path.config', $app->basePath() . DIRECTORY_SEPARATOR . 'config');
- $app->instance('path.storage', $app->basePath() . DIRECTORY_SEPARATOR . 'storage');
- $app->singleton(ExceptionHandler::class, LumenHandler::class);
- $app->singleton(Kernel::class, ConsoleKernel::class);
- $app->register(DataTablesServiceProvider::class);
- $app->withFacades(false, []);
-
- return $app;
- }
-
- /**
- * Set the testing connection for the application
- */
- private function setDatabase(): void
- {
- Schema::create('users', function (Blueprint $table) {
- $table->increments('id');
-
- $table->string('name');
- $table->string('email');
-
- $table->timestamps();
- });
- }
-
- private function setRoutes(Application $application): void
- {
- $application->router->get('get-route-no-action', 'MissingController@index');
- $application->router->get('users', UsersController::class . '@index');
- }
-}
\ No newline at end of file
diff --git a/tests/Unit/Controllers/Laravel/BaseControllerTest.php b/tests/Unit/Controllers/Laravel/BaseControllerTest.php
index 5010b11..fc0c995 100644
--- a/tests/Unit/Controllers/Laravel/BaseControllerTest.php
+++ b/tests/Unit/Controllers/Laravel/BaseControllerTest.php
@@ -1,13 +1,12 @@
controller = new BaseControllerWrapper;
@@ -25,10 +24,11 @@ public function setUp()
/**
* @test
- * @expectedException \Illuminate\Auth\Access\AuthorizationException
+ * @thros AuthorizationException
*/
public function check_access_should_be_called_if_the_environment_variable_is_set(): void
{
+ self::expectException(AuthorizationException::class);
$this->config->set('base-tree.authorization', true);
$this->request->setRouteResolver(function() {
return new Route([], '', ['uses' => BaseController::class . "@index"]);
@@ -47,4 +47,4 @@ public function check_access_should_not_be_called_if_the_action_method_is_exclud
$this->controller->testCheckAccess('view', DummyModel::class, new DummyModel);
$this->assertTrue(true);
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Controllers/Laravel/LaravelJsonControllerTest.php b/tests/Unit/Controllers/Laravel/LaravelJsonControllerTest.php
index 9bc9f3a..2e63b48 100644
--- a/tests/Unit/Controllers/Laravel/LaravelJsonControllerTest.php
+++ b/tests/Unit/Controllers/Laravel/LaravelJsonControllerTest.php
@@ -1,27 +1,28 @@
request->headers->set('accept', ['application/json']);
@@ -87,10 +88,12 @@ public function store_can_be_called_without_validation_rules(): void
/**
* @test
- * @expectedException \Illuminate\Validation\ValidationException
+ * @throws ValidationException
+ * @throws AuthorizationException
*/
public function store_should_throw_validation_exception_response_if_rules_does_not_match(): void
{
+ self::expectException(ValidationException::class);
$this->request->setMethod('POST');
$this->request->request->set('name', 'Dummy');
$instance = $this->controller('store', DummyResourceWithValidationsRules::class);
@@ -139,10 +142,12 @@ public function update_can_be_called_without_rules(): void
/**
* @test
- * @expectedException \Illuminate\Validation\ValidationException
+ * @throws ValidationException
+ * @throws AuthorizationException
*/
public function update_should_throw_validation_exception_response_if_rules_does_not_match(): void
{
+ self::expectException(ValidationException::class);
$this->request->setMethod('POST');
$this->request->request->set('name', 'Dummy');
$instance = $this->controller('update', DummyResourceWithValidationsRules::class);
@@ -192,10 +197,12 @@ public function destroy_can_be_called_without_rules(): void
/**
* @test
- * @expectedException \Illuminate\Validation\ValidationException
+ * @throws ValidationException
+ * @throws AuthorizationException
*/
public function destroy_should_throw_validation_exception_response_if_rules_does_not_match(): void
{
+ self::expectException(ValidationException::class);
$this->request->setMethod('DELETE');
$this->request->request->set('name', 'Dummy');
$instance = $this->controller('destroy', DummyResourceWithValidationsRules::class);
@@ -255,4 +262,4 @@ protected function arrayResponse(
/** @var JsonResponse $response */
return json_decode($response->content(), true);
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Controllers/WebControllerTest.php b/tests/Unit/Controllers/WebControllerTest.php
index 1aa6e3c..6194a4a 100644
--- a/tests/Unit/Controllers/WebControllerTest.php
+++ b/tests/Unit/Controllers/WebControllerTest.php
@@ -12,8 +12,10 @@
use BaseTree\Tests\Unit\TestCase;
use Illuminate\Http\Request;
use Illuminate\Routing\Route as LaravelRoute;
+use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
+use Illuminate\Validation\ValidationException;
use Mockery;
/**
@@ -92,12 +94,10 @@ public function web_store_can_be_called_without_validation_rules(): void
$this->assertEquals('http://localhost/dummies/index', $response->getTargetUrl());
}
- /**
- * @test
- * @expectedException \Illuminate\Validation\ValidationException
- */
+ /** @test */
public function web_store_should_throw_validation_exception_response_if_rules_does_not_match(): void
{
+ self::expectException(ValidationException::class);
$this->request->setMethod('POST');
$this->request->request->set('name', 'Dummy');
$instance = $this->controller('store', DummyResourceWithValidationsRules::class);
@@ -177,10 +177,10 @@ public function web_update_can_be_called_without_rules(): void
/**
* @test
- * @expectedException \Illuminate\Validation\ValidationException
*/
public function web_update_should_throw_validation_exception_response_if_rules_does_not_match(): void
{
+ self::expectException(ValidationException::class);
$this->request->setMethod('POST');
$this->request->request->set('name', 'Dummy');
$instance = $this->controller('update', DummyResourceWithValidationsRules::class);
@@ -236,10 +236,10 @@ public function web_destroy_can_be_called_without_rules(): void
/**
* @test
- * @expectedException \Illuminate\Validation\ValidationException
*/
public function web_destroy_should_throw_validation_exception_response_if_rules_does_not_match(): void
{
+ self::expectException(ValidationException::class);
$this->request->setMethod('DELETE');
$this->request->request->set('name', 'Dummy');
$instance = $this->controller('destroy', DummyResourceWithValidationsRules::class);
@@ -297,6 +297,6 @@ protected function assertSession(string $status, string $message): void
$session = session()->all();
$this->assertEquals($session['status'], $status);
$this->assertEquals($session['message'], $message);
- $this->assertEquals(array_get($session, '_flash.new'), ['status', 'message']);
+ $this->assertEquals(Arr::get($session, '_flash.new'), ['status', 'message']);
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Datatable/CreatorTest.php b/tests/Unit/Datatable/CreatorTest.php
index 5e56369..8e4e8c8 100644
--- a/tests/Unit/Datatable/CreatorTest.php
+++ b/tests/Unit/Datatable/CreatorTest.php
@@ -11,7 +11,7 @@
class CreatorTest extends TestCase
{
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->app->register(DataTablesServiceProvider::class);
@@ -26,4 +26,4 @@ public function creator_json_serialize_should_return_same_as_to_array(): void
$this->assertEquals($creator->toArray(), $creator->jsonSerialize());
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Eloquent/BaseEloquentTest.php b/tests/Unit/Eloquent/BaseEloquentTest.php
index c346ccd..62cd9e6 100644
--- a/tests/Unit/Eloquent/BaseEloquentTest.php
+++ b/tests/Unit/Eloquent/BaseEloquentTest.php
@@ -1,16 +1,16 @@
eloquentInstance()->findByConstraints([]);
}
@@ -70,10 +71,11 @@ public function paginated_should_return_pagination_from_injected_query(): void
/**
* @test
- * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
+ * @throws ModelNotFoundException
*/
- public function find_or_fail_should_throw_exception_if_there_arent_matching_results(): void
+ public function find_or_fail_should_throw_exception_if_there_are_not_matching_results(): void
{
+ self::expectException(ModelNotFoundException::class);
$instance = $this->eloquentInstance();
$this->model->shouldReceive('find')->with(1)->andReturn(null);
@@ -139,4 +141,4 @@ public function eloquentInstance(string $instance = EloquentDummy::class): BaseE
return new $instance($this->model);
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Exception/HttpHandlerTest.php b/tests/Unit/Exception/HttpHandlerTest.php
index bc2a610..12fbb6b 100644
--- a/tests/Unit/Exception/HttpHandlerTest.php
+++ b/tests/Unit/Exception/HttpHandlerTest.php
@@ -19,7 +19,7 @@ class HttpHandlerTest extends TestCase
*/
private $instance;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->instance = new LaravelHandler($this->app);
@@ -46,4 +46,4 @@ public function handle_http_render(): void
$this->instance->report($exception);
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Exception/JsonHandlerTest.php b/tests/Unit/Exception/JsonHandlerTest.php
index fb3c82f..71eae3b 100644
--- a/tests/Unit/Exception/JsonHandlerTest.php
+++ b/tests/Unit/Exception/JsonHandlerTest.php
@@ -30,7 +30,7 @@ class JsonHandlerTest extends TestCase
*/
private $validator;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->instance = new LaravelHandler($this->app);
@@ -104,4 +104,4 @@ public function exceptions()
[new Exception('Something bad happen.')]
];
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Resources/BaseResourceTest.php b/tests/Unit/Resources/BaseResourceTest.php
index 934608c..cf4ca5e 100644
--- a/tests/Unit/Resources/BaseResourceTest.php
+++ b/tests/Unit/Resources/BaseResourceTest.php
@@ -15,6 +15,7 @@
use BaseTree\Tests\Unit\TestCase;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Mockery;
@@ -31,7 +32,7 @@ class BaseResourceTest extends TestCase
*/
protected $instance;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->app->register(DataTablesServiceProvider::class);
@@ -87,10 +88,11 @@ public function index_should_return_datatable_response(): void
/**
* @test
- * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
+ * @throws ModelNotFoundException
*/
public function find_without_relationships_should_fail_if_entry_does_not_exists(): void
{
+ self::expectException(ModelNotFoundException::class);
$instance = $this->resourceInstance();
$this->model->shouldReceive('find')->with(1)->andReturn(null);
$instance->findWithoutRelations(1);
@@ -108,10 +110,11 @@ public function find_without_relationships_should_return_found_model(): void
/**
* @test
- * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException
+ * @throws ModelNotFoundException
*/
public function find_with_relations_should_fail_if_entry_does_not_exist(): void
{
+ self::expectException(ModelNotFoundException::class);
$instance = $this->resourceInstance();
$this->model->shouldReceive('find')->with(1)->andReturn(null);
diff --git a/tests/Unit/Responses/HttpResponseTest.php b/tests/Unit/Responses/HttpResponseTest.php
index 8aa3284..13b5669 100644
--- a/tests/Unit/Responses/HttpResponseTest.php
+++ b/tests/Unit/Responses/HttpResponseTest.php
@@ -18,7 +18,7 @@ class HttpResponseTest extends TestCase
*/
protected $instance;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->instance = new HttpResponse;
@@ -72,4 +72,4 @@ public function http_response_facade_is_registered(): void
$this->app->register(BaseTreeServiceProvider::class);
$this->assertInstanceOf(HttpResponse::class, $this->app->make('basetree.response.http'));
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Responses/JsonResponseTest.php b/tests/Unit/Responses/JsonResponseTest.php
index b67ac47..0e83c55 100644
--- a/tests/Unit/Responses/JsonResponseTest.php
+++ b/tests/Unit/Responses/JsonResponseTest.php
@@ -19,7 +19,7 @@ class JsonResponseTest extends TestCase
*/
protected $instance;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->instance = new JsonResponse;
@@ -219,4 +219,4 @@ public function response_should_try_to_call_the_logger_if_config_enables_it(): v
$this->instance->success();
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php
index 36545d2..137e8ae 100644
--- a/tests/Unit/TestCase.php
+++ b/tests/Unit/TestCase.php
@@ -19,10 +19,10 @@ abstract class TestCase extends LaravelTestCase
*/
protected $config;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
$this->request = $this->app->make(Request::class);
$this->config = $this->app->make(ConfigRepository::class);
}
-}
\ No newline at end of file
+}