Skip to content

Commit

Permalink
Test valid/invalid/empty yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
kasimi committed Oct 7, 2017
1 parent b453f68 commit 741328f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 15 deletions.
63 changes: 48 additions & 15 deletions tests/file_loader_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,62 @@
*
*/

use Phpbb\Epv\Files\FileLoader;
use Phpbb\Epv\Files\Type\LangFile;
use Phpbb\Epv\Files\Type\MigrationFile;
use Phpbb\Epv\Files\Type\PHPFile;
use Phpbb\Epv\Files\Type\PHPFileInterface;
use Phpbb\Epv\Files\Type\YmlFile;
use Phpbb\Epv\Tests\Mock\Output;

class file_loader_test extends PHPUnit_Framework_TestCase {

/** @var FileLoader */
private static $loader;

public static function setUpBeforeClass()
{
require_once('./tests/Mock/Output.php');

static::$loader = new FileLoader(new Output(), false, 'tests/testFiles/', '.');
}

private function getLoader()
public function test_file_php() {

$type = static::$loader->loadFile('tests/testFiles/test.txt.php');
$typePhp = static::$loader->loadFile('tests/testFiles/test.php');
$typeMigration = static::$loader->loadFile('tests/testFiles/migrations/test.php');

$this->assertTrue($type instanceof PHPFile);
$this->assertTrue($typePhp instanceof PHPFile);
$this->assertFalse($typePhp instanceof MigrationFile);
$this->assertFalse($typePhp instanceof LangFile);
$this->assertTrue($typeMigration instanceof PHPFileInterface); // It extends from the interface!
$this->assertTrue($typeMigration instanceof MigrationFile, 'type is migration file');
}

public function test_file_yml()
{
return $file = new \Phpbb\Epv\Files\FileLoader(new \Phpbb\Epv\Tests\Mock\Output(), false, 'tests/testFiles/', '.');
$validYml = static::$loader->loadFile('tests/testFiles/valid.yml');
$invalidImportYml = static::$loader->loadFile('tests/testFiles/invalid_import.yml');
$emptyImportYml = static::$loader->loadFile('tests/testFiles/empty_import.yml');

$this->assertTrue($validYml instanceof YmlFile);
$this->assertTrue($invalidImportYml instanceof YmlFile);
$this->assertTrue($emptyImportYml instanceof YmlFile);
}

public function test_file_php() {
$file = $this->getLoader();

$type = $file->loadFile('tests/testFiles/test.txt.php');
$typePhp = $file->loadFile('tests/testFiles/test.php');
$typeMigration = $file->loadFile('tests/testFiles/migrations/test.php');

$this->assertTrue($type instanceof \Phpbb\Epv\Files\Type\PHPFile);
$this->assertTrue($typePhp instanceof \Phpbb\Epv\Files\Type\PHPFile);
$this->assertFalse($typePhp instanceof \Phpbb\Epv\Files\Type\MigrationFile);
$this->assertFalse($typePhp instanceof \Phpbb\Epv\Files\Type\LangFile);
$this->assertTrue($typeMigration instanceof \Phpbb\Epv\Files\Type\PHPFileInterface); // It extends from the interface!
$this->assertTrue($typeMigration instanceof \Phpbb\Epv\Files\Type\MigrationFile, 'type is migration file');
public function test_file_invalid_yml()
{
$this->setExpectedException(Exception::class);
$invalidYml = static::$loader->loadFile('tests/testFiles/invalid.yml');
$this->assertNull($invalidYml);
}

public function test_file_empty_yml()
{
$this->setExpectedException(Exception::class);
$emptyYml = static::$loader->loadFile('tests/testFiles/empty.yml');
$this->assertNull($emptyYml);
}
}
Empty file added tests/testFiles/empty.yml
Empty file.
6 changes: 6 additions & 0 deletions tests/testFiles/empty_import.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
imports:
- { resource: empty.yml }

services:
some.service.name:
class: a\b\c
2 changes: 2 additions & 0 deletions tests/testFiles/invalid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
services:
some.
6 changes: 6 additions & 0 deletions tests/testFiles/invalid_import.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
imports:
- { resource: invalid.yml }

services:
some.service.name:
class: a\b\c
3 changes: 3 additions & 0 deletions tests/testFiles/valid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
some.service.name:
class: a\b\c

0 comments on commit 741328f

Please sign in to comment.