0
0

更新代码

This commit is contained in:
2020-08-04 10:24:44 +08:00
parent 00df028fb5
commit dfe2d107db
7848 changed files with 1002903 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace spec\Way\Generators\Compilers;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class TemplateCompilerSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Way\Generators\Compilers\TemplateCompiler');
}
function it_compiles_a_template_with_data()
{
$data = [
'NAME' => 'Foo',
'PARENT' => 'Bar'
];
$this->compile(
'class $NAME$ extends $PARENT$ {}', $data
) ->shouldBe('class Foo extends Bar {}');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace spec\Way\Generators;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Way\Generators\Filesystem\Filesystem;
use Way\Generators\Compilers\TemplateCompiler;
class GeneratorSpec extends ObjectBehavior {
function let(Filesystem $file)
{
// By default, we'll set the file to not exist
// This may be overridden, though
$file->exists('foo.txt')->willReturn(false);
$this->beConstructedWith($file);
}
function it_is_initializable()
{
$this->shouldHaveType('Way\Generators\Generator');
}
function it_compiles_a_template(Filesystem $file, TemplateCompiler $compiler)
{
$template = 'class $NAME$ {}';
$data = ['NAME' => 'Bar'];
$compiledTemplate = 'class Bar {}';
$file->get('template.txt')->shouldBeCalled()->willReturn($template);
$compiler->compile($template, $data)->shouldBeCalled()->willReturn($compiledTemplate);
// When we call compile, we expect the method to
// fetch the given template, compile it down,
// and return the results
$this->compile('template.txt', $data, $compiler)->shouldBe($compiledTemplate);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace spec\Way\Generators\Parsers;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MigrationFieldsParserSpec extends ObjectBehavior {
function it_is_initializable()
{
$this->shouldHaveType('Way\Generators\Parsers\MigrationFieldsParser');
}
function it_parses_a_string_of_fields()
{
$this->parse('name:string')->shouldReturn([
['field' => 'name', 'type' => 'string']
]);
$this->parse('name:string, age:integer')->shouldReturn([
['field' => 'name', 'type' => 'string'],
['field' => 'age', 'type' => 'integer']
]);
$this->parse('name:string:nullable, age:integer')->shouldReturn([
['field' => 'name', 'type' => 'string', 'decorators' => ['nullable']],
['field' => 'age', 'type' => 'integer']
]);
$this->parse('name:string(15):nullable')->shouldReturn([
['field' => 'name', 'type' => 'string', 'args' => '15', 'decorators' => ['nullable']]
]);
$this->parse('name:double(15,8):nullable:default(10), age:integer')->shouldReturn([
['field' => 'name', 'type' => 'double', 'args' => '15,8', 'decorators' => ['nullable', 'default(10)']],
['field' => 'age', 'type' => 'integer']
]);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace spec\Way\Generators\Parsers;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MigrationNameParserSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Way\Generators\Parsers\MigrationNameParser');
}
function it_parses_a_basic_migration_name()
{
$this->parse('create_orders_table')->shouldBe([
'action' => 'create',
'table' => 'orders'
]);
}
function it_parses_a_complex_migration_name()
{
$this->parse('add_first_name_and_last_name_to_recent_orders_table')->shouldBe([
'action' => 'add',
'table' => 'recent_orders'
]);
$this->parse('remove_first_name_from_users_table')->shouldBe([
'action' => 'remove',
'table' => 'users'
]);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace spec\Way\Generators;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Way\Generators\Compilers\TemplateCompiler;
use Way\Generators\Filesystem\Filesystem;
class SchemaCreatorSpec extends ObjectBehavior {
public function let(Filesystem $file, TemplateCompiler $compiler)
{
$this->beConstructedWith($file, $compiler);
}
function it_is_initializable()
{
$this->shouldHaveType('Way\Generators\SchemaCreator');
}
}