for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace App\Command\Fixture;
use App\Blog\Entity\PostTag;
use App\Blog\Entity\Tag;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Yiisoft\Yii\Console\ExitCode;
use Yiisoft\Yii\Cycle\Command\CycleDependencyProxy;
use App\Blog\Entity\Comment;
use App\Blog\Entity\Post;
use App\User\User;
final class SchemaClearCommand extends Command
{
protected static $defaultName = 'fixture/schema/clear';
private CycleDependencyProxy $promise;
public function __construct(
CycleDependencyProxy $promise,
) {
$this->promise = $promise;
parent::__construct();
}
public function configure(): void
$this
->setDescription('Clear database from fixtures')
->setHelp('This command delete all tables');
protected function execute(InputInterface $input, OutputInterface $output): int
$this->promise
->getDatabaseProvider()
->database()
->delete('post')
->run();
->delete('post_tag')
->delete('tag')
->delete('user')
->delete('comment')
return 0 === $this->promise
->getORM()
->getRepository(Post::class)
->select()
->count() +
->getRepository(PostTag::class)
->getRepository(Tag::class)
->getRepository(User::class)
->getRepository(Comment::class)
->count()
? ExitCode::OK
: ExitCode::UNSPECIFIED_ERROR;