CanConfigureMigrationCommandsTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Illuminate\Tests\Foundation\Testing\Traits;
  3. use Illuminate\Foundation\Testing\Traits\CanConfigureMigrationCommands;
  4. use PHPUnit\Framework\TestCase;
  5. class CanConfigureMigrationCommandsTest extends TestCase
  6. {
  7. protected $traitObject;
  8. protected function setup(): void
  9. {
  10. $this->traitObject = $this->getObjectForTrait(CanConfigureMigrationCommands::class);
  11. }
  12. private function __reflectAndSetupAccessibleForProtectedTraitMethod($methodName)
  13. {
  14. $migrateFreshUsingReflection = new \ReflectionMethod(
  15. get_class($this->traitObject),
  16. $methodName
  17. );
  18. $migrateFreshUsingReflection->setAccessible(true);
  19. return $migrateFreshUsingReflection;
  20. }
  21. public function testMigrateFreshUsingDefault(): void
  22. {
  23. $migrateFreshUsingReflection = $this->__reflectAndSetupAccessibleForProtectedTraitMethod('migrateFreshUsing');
  24. $expected = [
  25. '--drop-views' => false,
  26. '--drop-types' => false,
  27. '--seed' => false,
  28. ];
  29. $this->assertEquals($expected, $migrateFreshUsingReflection->invoke($this->traitObject));
  30. }
  31. public function testMigrateFreshUsingWithPropertySets(): void
  32. {
  33. $migrateFreshUsingReflection = $this->__reflectAndSetupAccessibleForProtectedTraitMethod('migrateFreshUsing');
  34. $expected = [
  35. '--drop-views' => true,
  36. '--drop-types' => false,
  37. '--seed' => false,
  38. ];
  39. $this->traitObject->dropViews = true;
  40. $this->assertEquals($expected, $migrateFreshUsingReflection->invoke($this->traitObject));
  41. $expected = [
  42. '--drop-views' => false,
  43. '--drop-types' => true,
  44. '--seed' => false,
  45. ];
  46. $this->traitObject->dropViews = false;
  47. $this->traitObject->dropTypes = true;
  48. $this->assertEquals($expected, $migrateFreshUsingReflection->invoke($this->traitObject));
  49. $expected = [
  50. '--drop-views' => true,
  51. '--drop-types' => true,
  52. '--seed' => false,
  53. ];
  54. $this->traitObject->dropViews = true;
  55. $this->traitObject->dropTypes = true;
  56. $this->assertEquals($expected, $migrateFreshUsingReflection->invoke($this->traitObject));
  57. }
  58. }