generated from yiisoft/package-template
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
3 changed files
with
143 additions
and
0 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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Cycle\Tests\Command\Schema; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Yiisoft\Test\Support\Container\SimpleContainer; | ||
use Yiisoft\Yii\Console\ExitCode; | ||
use Yiisoft\Yii\Cycle\Command\CycleDependencyProxy; | ||
use Yiisoft\Yii\Cycle\Command\Schema\SchemaClearCommand; | ||
use Yiisoft\Yii\Cycle\Schema\SchemaProviderInterface; | ||
|
||
final class SchemaClearBaseCommandTest extends TestCase | ||
{ | ||
public function testExecute(): void | ||
{ | ||
$schemaProvider = $this->getMockBuilder(SchemaProviderInterface::class)->getMock(); | ||
$schemaProvider->expects($this->once())->method('clear'); | ||
$container = new SimpleContainer([SchemaProviderInterface::class => $schemaProvider]); | ||
$promise = new CycleDependencyProxy($container); | ||
$command = new SchemaClearCommand($promise); | ||
$input = $this->getMockBuilder(InputInterface::class)->getMock(); | ||
$output = $this->getMockBuilder(OutputInterface::class)->getMock(); | ||
|
||
$code = $command->run($input, $output); | ||
|
||
$this->assertEquals(ExitCode::OK, $code); | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Cycle\Tests\Command\Schema; | ||
|
||
use Cycle\ORM\SchemaInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\Output; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Yiisoft\Test\Support\Container\SimpleContainer; | ||
use Yiisoft\Yii\Console\ExitCode; | ||
use Yiisoft\Yii\Cycle\Command\CycleDependencyProxy; | ||
use Yiisoft\Yii\Cycle\Command\Schema\SchemaCommand; | ||
|
||
final class SchemaCommandTest extends TestCase | ||
{ | ||
private OutputInterface $output; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->output = new class extends Output { | ||
private string $buffer = ''; | ||
|
||
protected function doWrite(string $message, bool $newline): void | ||
{ | ||
$this->buffer .= $message; | ||
|
||
if ($newline) { | ||
$this->buffer .= \PHP_EOL; | ||
} | ||
} | ||
|
||
public function getBuffer(): string | ||
{ | ||
return $this->buffer; | ||
} | ||
}; | ||
} | ||
|
||
public function testExecuteUndefinedRoles(): void | ||
{ | ||
$schema = $this->getMockBuilder(SchemaInterface::class)->getMock(); | ||
$schema->expects($this->any())->method('getRoles')->willReturn([]); | ||
|
||
$container = new SimpleContainer([SchemaInterface::class => $schema]); | ||
$promise = new CycleDependencyProxy($container); | ||
$command = new SchemaCommand($promise); | ||
|
||
$code = $command->run(new ArrayInput(['role' => 'foo,bar']), $this->output); | ||
|
||
$this->assertEquals(ExitCode::OK, $code); | ||
$this->assertStringContainsString('Undefined roles: foo, bar', $this->output->getBuffer()); | ||
} | ||
|
||
public function testExecuteGetRoles(): void | ||
{ | ||
$schema = $this->getMockBuilder(SchemaInterface::class)->getMock(); | ||
$schema->expects($this->any())->method('getRoles')->willReturn(['foo', 'bar']); | ||
$schema->expects($this->any())->method('define')->willReturnCallback( | ||
function (string $role, int $property) { | ||
if ($property === SchemaInterface::ROLE) { | ||
return $role; | ||
} | ||
|
||
return null; | ||
} | ||
); | ||
|
||
$container = new SimpleContainer([SchemaInterface::class => $schema]); | ||
$promise = new CycleDependencyProxy($container); | ||
$command = new SchemaCommand($promise); | ||
|
||
$code = $command->run(new ArrayInput([]), $this->output); | ||
|
||
$this->assertEquals(ExitCode::OK, $code); | ||
$this->assertStringNotContainsString('Undefined roles', $this->output->getBuffer()); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Yiisoft\Yii\Cycle\Tests\Command\Schema; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
use Yiisoft\Test\Support\Container\SimpleContainer; | ||
use Yiisoft\Yii\Console\ExitCode; | ||
use Yiisoft\Yii\Cycle\Command\CycleDependencyProxy; | ||
use Yiisoft\Yii\Cycle\Command\Schema\SchemaRebuildCommand; | ||
use Yiisoft\Yii\Cycle\Schema\SchemaProviderInterface; | ||
|
||
final class SchemaRebuildCommandTest extends TestCase | ||
{ | ||
public function testExecute() | ||
{ | ||
$provider = $this->getMockBuilder(SchemaProviderInterface::class)->getMock(); | ||
$provider->expects($this->once())->method('clear'); | ||
$provider->expects($this->once())->method('read'); | ||
|
||
$container = new SimpleContainer([SchemaProviderInterface::class => $provider]); | ||
$promise = new CycleDependencyProxy($container); | ||
|
||
$command = new SchemaRebuildCommand($promise); | ||
|
||
$code = $command->run(new ArrayInput([]), new BufferedOutput); | ||
|
||
$this->assertEquals(ExitCode::OK, $code); | ||
} | ||
} |