-
Notifications
You must be signed in to change notification settings - Fork 14
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 #13 from fullpipe/add-test
Add more tests
- Loading branch information
Showing
11 changed files
with
228 additions
and
37 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,44 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->exclude('tests') | ||
->in([__DIR__ . '/src']); | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@PSR1' => true, | ||
'@PSR2' => true, | ||
'@Symfony' => true, | ||
'@DoctrineAnnotation' => true, | ||
'psr4' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'mb_str_functions' => true, | ||
'no_null_property_initialization' => true, | ||
'no_php4_constructor' => true, | ||
'no_short_echo_tag' => true, | ||
'no_useless_else' => true, | ||
'no_useless_return' => true, | ||
'ordered_imports' => true, | ||
'strict_comparison' => false, | ||
'strict_param' => false, | ||
'native_function_invocation' => true, | ||
'phpdoc_add_missing_param_annotation' => true, | ||
'phpdoc_types_order' => true, | ||
'phpdoc_order' => true, | ||
'no_superfluous_phpdoc_tags' => [ | ||
'allow_mixed' => true, | ||
], | ||
'method_argument_space' => [ | ||
'on_multiline' => 'ensure_fully_multiline', | ||
], | ||
'explicit_string_variable' => true, | ||
'simple_to_complex_string_variable' => true, | ||
// extra | ||
'modernize_types_casting' => true, | ||
'method_chaining_indentation' => true, | ||
'linebreak_after_opening_tag' => true, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder($finder) | ||
->setUsingCache(false) | ||
; |
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,7 @@ | ||
language: php | ||
php: | ||
- '7.2' | ||
- '7.3' | ||
|
||
before_script: | ||
- composer install |
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
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,5 @@ | ||
{ | ||
"main.js": "main.js", | ||
"main.css": "main.css", | ||
"foo.png": "bar.png" | ||
} |
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,70 @@ | ||
<?php | ||
|
||
namespace tests\Fullpipe\TwigWebpackExtension\TokenParser; | ||
|
||
use Fullpipe\TwigWebpackExtension\TokenParser\EntryTokenParser; | ||
use Fullpipe\TwigWebpackExtension\TokenParser\EntryTokenParserCss; | ||
use PHPUnit\Framework\TestCase; | ||
use Twig\Environment; | ||
use Twig\Error\LoaderError; | ||
use Twig\Loader\LoaderInterface; | ||
use Twig\Node\TextNode; | ||
use Twig\Parser; | ||
use Twig\Source; | ||
|
||
class EntryTokenParserCssTest extends TestCase | ||
{ | ||
public function testItIsAParser() | ||
{ | ||
$this->assertInstanceOf(EntryTokenParser::class, new EntryTokenParserCss(__DIR__.'/../Resource/manifest.json', '/build/')); | ||
} | ||
|
||
public function testGenerate() | ||
{ | ||
$env = $this->getEnv(__DIR__.'/../Resource/manifest.json', '/build/'); | ||
$parser = new Parser($env); | ||
$source = new Source("{% webpack_entry_css 'main' %}", ''); | ||
$stream = $env->tokenize($source); | ||
|
||
$expected = new TextNode('<link type="text/css" href="/build/main.css" rel="stylesheet">', 1); | ||
$expected->setSourceContext($source); | ||
|
||
$this->assertEquals( | ||
$expected, | ||
$parser->parse($stream)->getNode('body')->getNode('0') | ||
); | ||
} | ||
|
||
public function testItThrowsExceptionIfNoManifest() | ||
{ | ||
$this->expectException(LoaderError::class); | ||
|
||
$env = $this->getEnv(__DIR__.'/../Resource/not_exists.json', '/build/'); | ||
$parser = new Parser($env); | ||
$source = new Source("{% webpack_entry_css 'main' %}", ''); | ||
$stream = $env->tokenize($source); | ||
$parser->parse($stream); | ||
} | ||
|
||
public function testItThrowsExceptionIfEntryNotExists() | ||
{ | ||
$this->expectException(LoaderError::class); | ||
|
||
$env = $this->getEnv(__DIR__.'/../Resource/manifest.json', '/build/'); | ||
$parser = new Parser($env); | ||
$source = new Source("{% webpack_entry_css 'not_exists' %}", ''); | ||
$stream = $env->tokenize($source); | ||
$parser->parse($stream); | ||
} | ||
|
||
private function getEnv(string $manifest, string $publicPath): Environment | ||
{ | ||
$env = new Environment( | ||
$this->getMockBuilder(LoaderInterface::class)->getMock(), | ||
['cache' => false, 'autoescape' => false, 'optimizations' => 0] | ||
); | ||
$env->addTokenParser(new EntryTokenParserCss($manifest, $publicPath)); | ||
|
||
return $env; | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace tests\Fullpipe\TwigWebpackExtension\TokenParser; | ||
|
||
use Fullpipe\TwigWebpackExtension\TokenParser\EntryTokenParserJs; | ||
use PHPUnit\Framework\TestCase; | ||
use Twig\Environment; | ||
use Twig\Loader\LoaderInterface; | ||
use Twig\Node\TextNode; | ||
use Twig\Parser; | ||
use Twig\Source; | ||
|
||
class EntryTokenParserJsTest extends TestCase | ||
{ | ||
public function testGenerate() | ||
{ | ||
$env = $this->getEnv(__DIR__.'/../Resource/manifest.json', '/build/'); | ||
$parser = new Parser($env); | ||
$source = new Source("{% webpack_entry_js 'main' %}", ''); | ||
$stream = $env->tokenize($source); | ||
|
||
$expected = new TextNode('<script type="text/javascript" src="/build/main.js"></script>', 1); | ||
$expected->setSourceContext($source); | ||
|
||
$this->assertEquals( | ||
$expected, | ||
$parser->parse($stream)->getNode('body')->getNode('0') | ||
); | ||
} | ||
|
||
private function getEnv(string $manifest, string $publicPath): Environment | ||
{ | ||
$env = new Environment( | ||
$this->getMockBuilder(LoaderInterface::class)->getMock(), | ||
['cache' => false, 'autoescape' => false, 'optimizations' => 0] | ||
); | ||
$env->addTokenParser(new EntryTokenParserJs($manifest, $publicPath)); | ||
|
||
return $env; | ||
} | ||
} |
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