Skip to content

Commit 1615834

Browse files
authored
Merge pull request #57 from RonasIT/add-nova-tests-generation
Add nova tests generation
2 parents 2111850 + 77bc95c commit 1615834

28 files changed

+1562
-278
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run tests with coverage
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
9+
jobs:
10+
test-with-coverage:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '7.4'
16+
- uses: actions/checkout@v3
17+
- name: Validate composer.json and composer.lock
18+
run: composer validate
19+
- name: Install Dependencies
20+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
21+
- name: Execute unit tests via PHPUnit with coverage
22+
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
23+
- name: Upload coverage results to Coveralls
24+
env:
25+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
composer global require php-coveralls/php-coveralls
28+
php-coveralls --coverage_clover=build/logs/clover.xml -v

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea
22
vendor/
3-
composer.lock
3+
composer.lock
4+
.phpunit.result.cache
5+
.phpunit.result.cache

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM webdevops/php-nginx-dev:7.4
2+
3+
RUN wget -O "/usr/local/bin/go-replace" "https://github.com/webdevops/goreplace/releases/download/1.1.2/gr-arm64-linux" \
4+
&& chmod +x "/usr/local/bin/go-replace" \
5+
&& "/usr/local/bin/go-replace" --version

bootstrap/autoload.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
define('LARAVEL_START', microtime(true));
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Register The Composer Auto Loader
8+
|--------------------------------------------------------------------------
9+
|
10+
| Composer provides a convenient, automatically generated class loader
11+
| for our application. We just need to utilize it! We'll require it
12+
| into the script here so that we do not have to worry about the
13+
| loading of any our classes "manually". Feels great to relax.
14+
|
15+
*/
16+
17+
require __DIR__.'/../vendor/autoload.php';
18+
19+
/*
20+
|--------------------------------------------------------------------------
21+
| Include The Compiled Class File
22+
|--------------------------------------------------------------------------
23+
|
24+
| To dramatically increase your application's performance, you may use a
25+
| compiled class file which contains all of the classes commonly used
26+
| by a request. The Artisan "optimize" is used to create this file.
27+
|
28+
*/
29+
30+
$compiledPath = __DIR__.'/cache/compiled.php';
31+
32+
if (file_exists($compiledPath)) {
33+
require $compiledPath;
34+
}

bootstrap/cache/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

composer.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,34 @@
1111
],
1212
"require": {
1313
"php": ">=7.1.3",
14-
"laravel/framework": ">=5.4.0",
15-
"ronasit/laravel-helpers": ">=2.0.0-beta",
14+
"laravel/framework": ">=5.7.0",
15+
"ronasit/laravel-helpers": ">=2.5",
1616
"laravel/legacy-factories": ">=1.3.0",
1717
"ext-json": "*"
1818
},
1919
"require-dev": {
2020
"fzaninotto/faker": "~1.4",
21-
"mockery/mockery": "0.9.*",
22-
"phpunit/phpunit": "~4.0"
21+
"php-coveralls/php-coveralls": "^2.5",
22+
"mockery/mockery": "^1.4",
23+
"phpunit/phpunit": "^8.0",
24+
"mikey179/vfsstream": "^1.6.11",
25+
"php-mock/php-mock": "^2.4.1",
26+
"orchestra/testbench": "^6.25"
2327
},
2428
"autoload": {
2529
"psr-4": {
30+
"RonasIT\\Support\\Tests\\": "tests/",
2631
"RonasIT\\Support\\": "src/"
2732
},
2833
"files": [
2934
"src/helpers.php"
3035
]
3136
},
37+
"autoload-dev": {
38+
"files": [
39+
"tests/TestCase.php"
40+
]
41+
},
3242
"minimum-stability": "beta",
3343
"extra": {
3444
"laravel": {

config/entity-generator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'factory' => 'database/factories/ModelFactory.php',
2020
'translations' => 'resources/lang/en/validation.php',
2121
'resources' => 'app/Http/Resources',
22-
'nova' => 'app/Nova'
22+
'nova' => 'app/Nova',
2323
],
2424
'stubs' => [
2525
'model' => 'entity-generator::model',
@@ -44,6 +44,7 @@
4444
'validation' => 'entity-generator::validation',
4545
'resource' => 'entity-generator::resource',
4646
'collection_resource' => 'entity-generator::collection_resource',
47-
'nova_resource' => 'entity-generator::nova_resource'
47+
'nova_resource' => 'entity-generator::nova_resource',
48+
'nova_test' => 'entity-generator::nova_test'
4849
]
4950
];

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
3+
services:
4+
nginx:
5+
build: .
6+
working_dir: /app
7+
ports:
8+
- 80:80
9+
- 443:443
10+
volumes:
11+
- ./:/app

phpunit.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="bootstrap/autoload.php"
4+
colors="true"
5+
cacheResultFile=".phpunit.cache"
6+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd">
7+
<testsuites>
8+
<testsuite name="Application Test Suite">
9+
<directory>./tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<filter>
13+
<whitelist>
14+
<directory suffix=".php">./src</directory>
15+
<directory suffix=".php">./tests</directory>
16+
<exclude>
17+
<directory>./tests/fixtures</directory>
18+
<file>./tests/TestCase.php</file>
19+
</exclude>
20+
</whitelist>
21+
</filter>
22+
<php>
23+
<env name="APP_ENV" value="testing"/>
24+
<env name="CACHE_DRIVER" value="array"/>
25+
<env name="SESSION_DRIVER" value="array"/>
26+
<env name="QUEUE_DRIVER" value="sync"/>
27+
</php>
28+
29+
</phpunit>

src/Commands/MakeEntityCommand.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use RonasIT\Support\Generators\MigrationGenerator;
1616
use RonasIT\Support\Generators\ModelGenerator;
1717
use RonasIT\Support\Generators\NovaResourceGenerator;
18+
use RonasIT\Support\Generators\NovaTestGenerator;
1819
use RonasIT\Support\Generators\RepositoryGenerator;
1920
use RonasIT\Support\Generators\RequestsGenerator;
2021
use RonasIT\Support\Generators\ResourceGenerator;
@@ -38,6 +39,7 @@
3839
* @property SeederGenerator $seederGenerator
3940
* @property ResourceGenerator $resourceGenerator
4041
* @property NovaResourceGenerator $novaResourceGenerator
42+
* @property NovaTestGenerator $novaTestGenerator
4143
* @property EventDispatcher $eventDispatcher
4244
*/
4345
class MakeEntityCommand extends Command
@@ -66,6 +68,7 @@ class MakeEntityCommand extends Command
6668
{--only-tests : Set this flag if you want to create only tests.}
6769
{--only-seeder : Set this flag if you want to create only seeder.}
6870
{--only-nova-resource : Set this flag if you want to create only nova resource.}
71+
{--only-nova-tests : Set this flag if you want to create only nova resource tests.}
6972
7073
{--methods=CRUD : Set types of methods to create. Affect on routes, requests classes, controller\'s methods and tests methods.}
7174
@@ -105,6 +108,7 @@ class MakeEntityCommand extends Command
105108
protected $seederGenerator;
106109
protected $resourceGenerator;
107110
protected $novaResourceGenerator;
111+
protected $novaTestGenerator;
108112
protected $eventDispatcher;
109113

110114
protected $rules = [
@@ -121,14 +125,16 @@ class MakeEntityCommand extends Command
121125
'only-factory' => [FactoryGenerator::class],
122126
'only-tests' => [FactoryGenerator::class, TestsGenerator::class],
123127
'only-seeder' => [SeederGenerator::class],
124-
'only-nova-resource' => [NovaResourceGenerator::class]
128+
'only-nova-resource' => [NovaResourceGenerator::class],
129+
'only-nova-tests' => [NovaTestGenerator::class]
125130
]
126131
];
127132

128133
public $generators = [
129134
ModelGenerator::class, RepositoryGenerator::class, ServiceGenerator::class, RequestsGenerator::class,
130135
ResourceGenerator::class, ControllerGenerator::class, MigrationGenerator::class, FactoryGenerator::class,
131-
TestsGenerator::class, TranslationsGenerator::class, SeederGenerator::class, NovaResourceGenerator::class
136+
TestsGenerator::class, TranslationsGenerator::class, SeederGenerator::class, NovaResourceGenerator::class,
137+
NovaTestGenerator::class
132138
];
133139

134140
public function __construct()
@@ -147,6 +153,7 @@ public function __construct()
147153
$this->seederGenerator = app(SeederGenerator::class);
148154
$this->resourceGenerator = app(ResourceGenerator::class);
149155
$this->novaResourceGenerator = app(NovaResourceGenerator::class);
156+
$this->novaTestGenerator = app(NovaTestGenerator::class);
150157
$this->eventDispatcher = app(EventDispatcher::class);
151158
}
152159

0 commit comments

Comments
 (0)