Skip to content

Commit

Permalink
add Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
howyi committed Oct 17, 2017
1 parent 6d50248 commit 10b739f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
4 changes: 1 addition & 3 deletions conv.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
default:
engine: InnoDB
engine: InnoDB
charset: utf8mb4
collate: utf8mb4_bin
option:
eval: true
2 changes: 1 addition & 1 deletion src/Conv/Util/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final public static function __callStatic(string $key, array $arg)
{
static $config;
if (is_null($config)) {
$path = getcwd() . DIRECTORY_SEPARATOR . 'conv.yml';
$path = getcwd() . '/' . 'conv.yml';
if (file_exists($path)) {
$config = Evi::parse($path, true);
} else {
Expand Down
26 changes: 26 additions & 0 deletions tests/Conv/Util/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Conv\Util;

use Symfony\Component\Yaml\Yaml;

class ConfigTest extends \PHPUnit\Framework\TestCase
{
public function testConstruct()
{
$c = new Config();
$this->assertSame($c::DEFAULT['default']['engine'], $c::default('engine'));
$this->assertSame($c::DEFAULT['default']['engine'], $c::default('engine'));
$this->assertSame($c::DEFAULT['option']['eval'], $c::option('eval'));
}

public function testConstructNoConfigFile()
{
unlink('conv.yml');
$c = new Config();
$this->assertSame($c::DEFAULT['default']['engine'], $c::default('engine'));
$config = $c::DEFAULT;
unset($config['option']);
file_put_contents('conv.yml', Yaml::dump($config));
}
}
46 changes: 46 additions & 0 deletions tests/Conv/Util/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ public function testValidateFailed($array)
public function validateFailedProvider()
{
return [
[
[
SchemaKey::TABLE_TYPE => TableStructureType::TABLE,
SchemaKey::TABLE_COMMENT => 'Music management table',
SchemaKey::TABLE_COLUMN => [
'music_id' => [
SchemaKey::COLUMN_COMMENT => 'Unique music ID',
],
'name' => [
SchemaKey::COLUMN_TYPE => 'int(10)',
SchemaKey::COLUMN_COMMENT => 'Music name',
],
],
SchemaKey::TABLE_PRIMARY_KEY => [
'music_id'
]
]
],
[
[
SchemaKey::TABLE_COLUMN => [
Expand Down Expand Up @@ -105,6 +123,34 @@ public function validateFailedProvider()
]
]
],
[
[
SchemaKey::TABLE_TYPE => TableStructureType::TABLE,
SchemaKey::TABLE_COMMENT => 'Music management table',
SchemaKey::TABLE_COLUMN => [
'music_id' => [
SchemaKey::COLUMN_TYPE => 'int(10)',
SchemaKey::COLUMN_COMMENT => 'Unique music ID',
],
'name' => [
SchemaKey::COLUMN_TYPE => 'int(10)',
SchemaKey::COLUMN_COMMENT => 'Music name',
],
],
SchemaKey::TABLE_PRIMARY_KEY => [
'music_id'
],
SchemaKey::TABLE_INDEX => [
'music_id' => [
SchemaKey::INDEX_TYPE => true,
SchemaKey::INDEX_COLUMN => [
'music_id',
'music_id',
]
]
]
]
],
];
}
}

0 comments on commit 10b739f

Please sign in to comment.