-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from tienvx/testing
Add unit tests
- Loading branch information
Showing
14 changed files
with
246 additions
and
52 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,42 @@ | ||
name: main | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-versions: ['7.4', '8.0'] | ||
name: PHP ${{ matrix.php-versions }} | ||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
coverage: pcov | ||
tools: phpstan, php-cs-fixer:3, phpunit, composer:v2 | ||
#extensions: mbstring, intl | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install | ||
run: composer install --prefer-source | ||
|
||
- name: Run PHP CS Fixer | ||
run: php-cs-fixer fix --diff --dry-run | ||
|
||
- name: Run PHPStan | ||
run: phpstan analyse src tests | ||
|
||
- name: Test & Generate Code Coverage | ||
run: phpunit | ||
|
||
- name: Upload coverage results to Coveralls | ||
env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
composer global require php-coveralls/php-coveralls | ||
php-coveralls --coverage_clover=clover.xml -v | ||
if: matrix.php-versions == '7.4' |
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
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,9 @@ | ||
<?php | ||
|
||
namespace Tienvx\UX\CollectionJs; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class CollectionJsBundle extends Bundle | ||
{ | ||
} |
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use Tienvx\UX\CollectionJs\Form\CollectionJsType; | ||
|
||
return static function (ContainerConfigurator $container): void { | ||
$container->services() | ||
->set(CollectionJsType::class) | ||
->tag('form.type') | ||
; | ||
}; |
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 Tienvx\UX\CollectionJs\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use Tienvx\UX\CollectionJs\Tests\Kernel\EmptyAppKernel; | ||
use Tienvx\UX\CollectionJs\Tests\Kernel\FrameworkAppKernel; | ||
|
||
class CollectionJsBundleTest extends TestCase | ||
{ | ||
public function provideKernels() | ||
{ | ||
yield 'empty' => [new EmptyAppKernel('test', true)]; | ||
yield 'framework' => [new FrameworkAppKernel('test', true)]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideKernels | ||
*/ | ||
public function testBootKernel(Kernel $kernel) | ||
{ | ||
$kernel->boot(); | ||
$this->assertArrayHasKey('CollectionJsBundle', $kernel->getBundles()); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace Tienvx\UX\CollectionJs\Tests\Form; | ||
|
||
use Symfony\Component\Form\Tests\Extension\Core\Type\CollectionTypeTest; | ||
use Symfony\Component\Form\Tests\Extension\Core\Type\FileTypeTest; | ||
use Symfony\Component\Form\Tests\Extension\Core\Type\TextTypeTest; | ||
use Tienvx\UX\CollectionJs\Form\CollectionJsType; | ||
|
||
class CollectionJsTypeTest extends CollectionTypeTest | ||
{ | ||
public const TESTED_TYPE = CollectionJsType::class; | ||
|
||
public function testDefaultOptions() | ||
{ | ||
$form = $this->factory | ||
->create(static::TESTED_TYPE, null, [ | ||
'entry_type' => FileTypeTest::TESTED_TYPE, | ||
]) | ||
; | ||
|
||
$view = $form->createView(); | ||
$this->assertFalse($view->vars['allow_move_up']); | ||
$this->assertFalse($view->vars['allow_move_down']); | ||
$this->assertFalse($view->vars['render_expanded']); | ||
} | ||
|
||
public function testCustomOptions() | ||
{ | ||
$form = $this->factory | ||
->create(static::TESTED_TYPE, null, [ | ||
'entry_type' => TextTypeTest::TESTED_TYPE, | ||
'allow_move_up' => true, | ||
'allow_move_down' => true, | ||
'render_expanded' => true, | ||
]) | ||
; | ||
|
||
$view = $form->createView(); | ||
$this->assertTrue($view->vars['allow_move_up']); | ||
$this->assertTrue($view->vars['allow_move_down']); | ||
$this->assertTrue($view->vars['render_expanded']); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Tienvx\UX\CollectionJs\Tests\Kernel; | ||
|
||
trait AppKernelTrait | ||
{ | ||
public function getCacheDir() | ||
{ | ||
return $this->createTmpDir('cache'); | ||
} | ||
|
||
public function getLogDir() | ||
{ | ||
return $this->createTmpDir('logs'); | ||
} | ||
|
||
private function createTmpDir(string $type): string | ||
{ | ||
$dir = sys_get_temp_dir() . '/collection_js_bundle/' . uniqid($type . '_', true); | ||
|
||
if (!file_exists($dir)) { | ||
mkdir($dir, 0777, true); | ||
} | ||
|
||
return $dir; | ||
} | ||
} |
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 Tienvx\UX\CollectionJs\Tests\Kernel; | ||
|
||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use Tienvx\UX\CollectionJs\CollectionJsBundle; | ||
|
||
class EmptyAppKernel extends Kernel | ||
{ | ||
use AppKernelTrait; | ||
|
||
public function registerBundles() | ||
{ | ||
return [new CollectionJsBundle()]; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
} | ||
} |
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 Tienvx\UX\CollectionJs\Tests\Kernel; | ||
|
||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use Tienvx\UX\CollectionJs\CollectionJsBundle; | ||
|
||
class FrameworkAppKernel extends Kernel | ||
{ | ||
use AppKernelTrait; | ||
|
||
public function registerBundles() | ||
{ | ||
return [new FrameworkBundle(), new CollectionJsBundle()]; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
$loader->load(function (ContainerBuilder $container) { | ||
$container->loadFromExtension('framework', ['secret' => '$ecret', 'test' => true]); | ||
}); | ||
} | ||
} |