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
7 changed files
with
67 additions
and
2 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
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,8 @@ | ||
<?php | ||
|
||
namespace Overblog\GraphQLBundle\Tests\Config\Parser; | ||
|
||
class Constant | ||
{ | ||
const CONSTANT = 1; | ||
} |
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,52 @@ | ||
<?php | ||
|
||
namespace Overblog\GraphQLBundle\Tests\Config\Parser; | ||
|
||
use Overblog\GraphQLBundle\Config\Parser\YamlParser; | ||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
|
||
class YamlParserTest extends TestCase | ||
{ | ||
/** @var ContainerBuilder|\PHPUnit_Framework_MockObject_MockObject */ | ||
private $containerBuilder; | ||
|
||
public function setUp() | ||
{ | ||
$this->containerBuilder = $this->getMockBuilder(ContainerBuilder::class)->setMethods(['addResource'])->getMock(); | ||
} | ||
|
||
public function testParseEmptyFile() | ||
{ | ||
$fileName = __DIR__.'/fixtures/yml/empty.yml'; | ||
|
||
$this->assertContainerAddFileToResources($fileName); | ||
|
||
$config = YamlParser::parse(new \SplFileInfo($fileName), $this->containerBuilder); | ||
$this->assertEquals([], $config); | ||
} | ||
|
||
public function testParseInvalidFile() | ||
{ | ||
$fileName = __DIR__.'/fixtures/yml/invalid.yml'; | ||
file_put_contents($fileName, iconv('UTF-8', 'ISO-8859-1', "not_utf-8: 'äöüß'")); | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage(sprintf('The file "%s" does not contain valid YAML.', $fileName)); | ||
YamlParser::parse(new \SplFileInfo($fileName), $this->containerBuilder); | ||
} | ||
|
||
public function testParseConstant() | ||
{ | ||
$expected = ['values' => ['constant' => Constant::CONSTANT]]; | ||
$actual = YamlParser::parse(new \SplFileInfo(__DIR__.'/fixtures/yml/constant.yml'), $this->containerBuilder); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
private function assertContainerAddFileToResources($fileName) | ||
{ | ||
$this->containerBuilder->expects($this->once()) | ||
->method('addResource') | ||
->with($fileName); | ||
} | ||
} |
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,2 @@ | ||
values: | ||
constant: !php/const Overblog\GraphQLBundle\Tests\Config\Parser\Constant::CONSTANT |
Empty file.
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 @@ | ||
not_utf-8: '����' |