-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
235 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Run Unit Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: [8.0, 8.1, 8.2, 8.3] | ||
laravel: [10.*, 11.*] | ||
dependency-version: [prefer-lowest, prefer-stable] | ||
exclude: | ||
- laravel: 10.* | ||
php: 8.0 | ||
- laravel: 11.* | ||
php: 8.0 | ||
- laravel: 11.* | ||
php: 8.1 | ||
|
||
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{matrix.php}} | ||
|
||
- name: Get Composer cache directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
- name: Cache Composer dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
# Use composer.json for key, if composer.lock is not committed. | ||
key: php-${{ matrix.php }}-lara-${{ matrix.laravel }}-composer-${{ matrix.dependency-version }}-${{ hashFiles('**/composer.json') }} | ||
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: php-${{ matrix.php }}-lara-${{ matrix.laravel }}-composer-${{ matrix.dependency-version }}- | ||
|
||
- name: Install Composer dependencies | ||
run: | | ||
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update | ||
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction | ||
- name: Run PHPUnit tests | ||
run: vendor/bin/phpunit --testdox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
build/ | ||
vendor/ | ||
composer.lock | ||
composer.lock | ||
*.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
backupGlobals="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing" force="true"/> | ||
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/> | ||
<env name="DB_CONNECTION" value="testing"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace NorbyBaru\Modularize\Tests\Commands; | ||
|
||
use NorbyBaru\Modularize\Tests\MakeCommandTestCase; | ||
|
||
class MakeModelCommandTest extends MakeCommandTestCase | ||
{ | ||
public function test_it_creates_a_model() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:model', | ||
parameters: [ | ||
'name' => 'Post', | ||
'--module' => $this->moduleName, | ||
] | ||
) | ||
->assertSuccessful(); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Models/Post.php'); | ||
} | ||
|
||
public function test_it_creates_a_model_with_migration() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:model', | ||
parameters: [ | ||
'name' => 'Post', | ||
'--module' => $this->moduleName, | ||
'--migration' => true, | ||
] | ||
) | ||
->assertExitCode(exitCode: 0); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Models/Post.php'); | ||
$this->assertFileExists(filename: $this->getModulePath().'/Database/migration/'.date('Y_m_d_His').'_create_posts_table.php'); | ||
} | ||
|
||
public function test_it_creates_a_model_with_factory() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:model', | ||
parameters: [ | ||
'name' => 'Post', | ||
'--module' => $this->moduleName, | ||
//'--factory' => true | ||
] | ||
) | ||
->assertExitCode(exitCode: 0); | ||
|
||
$this->assertFileExists(filename: $this->getModulePath().'/Models/Post.php'); | ||
//$this->assertFileExists($this->getModulePath($this->moduleName).'/Database/Factories/PostFactory.php'); | ||
} | ||
|
||
public function test_it_creates_a_model_with_migration_and_factory() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:model', | ||
parameters: [ | ||
'name' => 'Post', | ||
'--module' => $this->moduleName, | ||
'--migration' => true, | ||
//'--factory' => true | ||
] | ||
) | ||
->assertExitCode(exitCode: 0); | ||
|
||
$this->assertFileExists( | ||
filename: $this->getModulePath().'/Models/Post.php' | ||
); | ||
$this->assertFileExists( | ||
filename: $this->getModulePath().'/Database/migration/'.date('Y_m_d_His').'_create_posts_table.php' | ||
); | ||
//$this->assertFileExists($this->getModulePath($this->moduleName).'/Database/factories/PostFactory.php'); | ||
} | ||
|
||
public function test_it_creates_a_model_with_migration_and_factory_and_test() | ||
{ | ||
$this->artisan( | ||
command: 'module:make:model', | ||
parameters: [ | ||
'name' => 'Post', | ||
'--module' => $this->moduleName, | ||
'--migration' => true, | ||
'--factory' => true, | ||
//'--test' => true | ||
]) | ||
->assertExitCode(exitCode: 0); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace NorbyBaru\Modularize\Tests; | ||
|
||
abstract class MakeCommandTestCase extends TestCase | ||
{ | ||
public string $moduleName = 'Blog'; | ||
|
||
public function teardown(): void | ||
{ | ||
$this->cleanUp(); | ||
parent::tearDown(); | ||
} | ||
|
||
public function getModulePath(?string $module = null): string | ||
{ | ||
$module = $module ?? $this->moduleName; | ||
|
||
return parent::getModulePath($module); | ||
} | ||
|
||
public function cleanUp(): void | ||
{ | ||
$this->app['files']->deleteDirectory($this->getModulePath(module: $this->moduleName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace NorbyBaru\Modularize\Tests; | ||
|
||
use NorbyBaru\Modularize\ModularizeServiceProvider; | ||
use Orchestra\Testbench\TestCase as OrchestraTestCase; | ||
|
||
abstract class TestCase extends OrchestraTestCase | ||
{ | ||
public function getModulePath(string $module): string | ||
{ | ||
return base_path(config('modularize.root_path')."/$module"); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
ModularizeServiceProvider::class, | ||
]; | ||
} | ||
} |