DatabaseShowTablesCommandTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Test\PhpDevCommunity\PaperORM;
  3. use PhpDevCommunity\Console\CommandParser;
  4. use PhpDevCommunity\Console\CommandRunner;
  5. use PhpDevCommunity\Console\Output;
  6. use PhpDevCommunity\PaperORM\Command\ShowTablesCommand;
  7. use PhpDevCommunity\PaperORM\EntityManager;
  8. use PhpDevCommunity\PaperORM\Mapping\Column\BoolColumn;
  9. use PhpDevCommunity\PaperORM\Mapping\Column\IntColumn;
  10. use PhpDevCommunity\PaperORM\Mapping\Column\JoinColumn;
  11. use PhpDevCommunity\PaperORM\Mapping\Column\PrimaryKeyColumn;
  12. use PhpDevCommunity\PaperORM\Mapping\Column\StringColumn;
  13. use PhpDevCommunity\UniTester\TestCase;
  14. use Test\PhpDevCommunity\PaperORM\Entity\UserTest;
  15. class DatabaseShowTablesCommandTest extends TestCase
  16. {
  17. private EntityManager $em;
  18. protected function setUp(): void
  19. {
  20. $this->em = new EntityManager([
  21. 'driver' => 'sqlite',
  22. 'user' => null,
  23. 'password' => null,
  24. 'memory' => true,
  25. ]);
  26. }
  27. protected function tearDown(): void
  28. {
  29. $this->em->getConnection()->close();
  30. }
  31. protected function execute(): void
  32. {
  33. $platform = $this->em->createDatabasePlatform();
  34. $platform->createTable('user', [
  35. new PrimaryKeyColumn('id'),
  36. new StringColumn('firstname'),
  37. new StringColumn('lastname'),
  38. new StringColumn('email'),
  39. new StringColumn('password'),
  40. new BoolColumn('is_active'),
  41. ]);
  42. $platform->createTable('post', [
  43. new PrimaryKeyColumn('id'),
  44. new JoinColumn('user_id', 'id', UserTest::class),
  45. new StringColumn('title'),
  46. new StringColumn('content'),
  47. ]);
  48. $runner = new CommandRunner([
  49. new ShowTablesCommand($this->em)
  50. ]);
  51. $code = $runner->run(new CommandParser(['', 'paper:show:tables', '--columns']), new Output(function ($message) use(&$countMessages) {
  52. }));
  53. $this->assertEquals(0, $code);
  54. }
  55. }