simple_test.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * Simplified Test Script for SixShop Maker Bundle
  4. * Tests the actual working functionality
  5. */
  6. // Autoload classes
  7. if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
  8. require __DIR__ . '/../vendor/autoload.php';
  9. } elseif (file_exists(__DIR__ . '/../../../../autoload.php')) {
  10. require __DIR__ . '/../../../../autoload.php';
  11. } else {
  12. echo "Error: Composer autoload not found.\n";
  13. exit(1);
  14. }
  15. use SixShop\MakerBundle\Generator\MigrationGenerator;
  16. echo "🧪 SixShop Maker Bundle - Basic Functionality Test\n";
  17. echo "=" . str_repeat("=", 50) . "\n\n";
  18. $testDir = sys_get_temp_dir() . '/sixshop_basic_test_' . time();
  19. $passed = 0;
  20. $failed = 0;
  21. function test(string $name, callable $test): void
  22. {
  23. global $passed, $failed;
  24. echo "📋 Testing: {$name}... ";
  25. try {
  26. $result = $test();
  27. if ($result) {
  28. echo "✅ PASSED\n";
  29. $passed++;
  30. } else {
  31. echo "❌ FAILED\n";
  32. $failed++;
  33. }
  34. } catch (Exception $e) {
  35. echo "💥 ERROR: " . $e->getMessage() . "\n";
  36. $failed++;
  37. }
  38. }
  39. function setupTestDir(): string
  40. {
  41. global $testDir;
  42. if (!is_dir($testDir)) {
  43. mkdir($testDir, 0755, true);
  44. }
  45. return $testDir;
  46. }
  47. function cleanupTestDir(): void
  48. {
  49. global $testDir;
  50. if (is_dir($testDir)) {
  51. $iterator = new RecursiveIteratorIterator(
  52. new RecursiveDirectoryIterator($testDir, RecursiveDirectoryIterator::SKIP_DOTS),
  53. RecursiveIteratorIterator::CHILD_FIRST
  54. );
  55. foreach ($iterator as $file) {
  56. if ($file->isDir()) {
  57. rmdir($file->getRealPath());
  58. } else {
  59. unlink($file->getRealPath());
  60. }
  61. }
  62. rmdir($testDir);
  63. }
  64. }
  65. // Test 1: Basic MigrationGenerator functionality
  66. test("MigrationGenerator - Create Table", function() {
  67. $testDir = setupTestDir();
  68. $generator = new MigrationGenerator($testDir . '/migrations');
  69. $fields = [
  70. ['name' => 'id', 'type' => 'biginteger', 'null' => false],
  71. ['name' => 'name', 'type' => 'string', 'length' => 100, 'null' => false],
  72. ['name' => 'email', 'type' => 'string', 'length' => 255, 'null' => false, 'unique' => true]
  73. ];
  74. $result = $generator->generateMigration('users', $fields, 'create');
  75. if (!$result) {
  76. return false;
  77. }
  78. // Check if file was created
  79. $files = glob($testDir . '/migrations/*_create_users_table.php');
  80. return count($files) === 1;
  81. });
  82. test("MigrationGenerator - Supported Field Types", function() {
  83. $generator = new MigrationGenerator();
  84. $supportedTypes = $generator->getSupportedFieldTypes();
  85. $requiredTypes = ['string', 'integer', 'biginteger', 'text', 'boolean', 'decimal', 'json', 'timestamp'];
  86. foreach ($requiredTypes as $type) {
  87. if (!in_array($type, $supportedTypes)) {
  88. return false;
  89. }
  90. }
  91. return true;
  92. });
  93. test("MigrationGenerator - Complex Field Options", function() {
  94. $testDir = setupTestDir();
  95. $generator = new MigrationGenerator($testDir . '/migrations');
  96. $fields = [
  97. [
  98. 'name' => 'price',
  99. 'type' => 'decimal',
  100. 'precision' => 10,
  101. 'scale' => 2,
  102. 'null' => false,
  103. 'comment' => 'Product price'
  104. ],
  105. [
  106. 'name' => 'config',
  107. 'type' => 'json',
  108. 'null' => true,
  109. 'comment' => 'Configuration data'
  110. ]
  111. ];
  112. $result = $generator->generateMigration('products', $fields, 'create');
  113. if (!$result) {
  114. return false;
  115. }
  116. // Check if file was created and contains the expected content
  117. $files = glob($testDir . '/migrations/*_create_products_table.php');
  118. if (count($files) !== 1) {
  119. return false;
  120. }
  121. $content = file_get_contents($files[0]);
  122. return strpos($content, 'decimal') !== false &&
  123. strpos($content, 'json') !== false &&
  124. strpos($content, 'precision') !== false;
  125. });
  126. test("CLI Command Availability", function() {
  127. $binPath = __DIR__ . '/../bin/sixshop-maker';
  128. if (!file_exists($binPath)) {
  129. return false;
  130. }
  131. // Check if file is executable
  132. return is_executable($binPath);
  133. });
  134. test("Template Files Exist", function() {
  135. $requiredTemplates = [
  136. 'composer.json.tpl.php',
  137. 'config.php.tpl.php',
  138. 'info.php.tpl.php',
  139. 'src/Controller/Admin/Controller.php.tpl.php',
  140. 'src/Controller/Api/Controller.php.tpl.php',
  141. 'src/Entity/Entity.php.tpl.php',
  142. 'src/Model/Model.php.tpl.php'
  143. ];
  144. $templateDir = __DIR__ . '/../templates/';
  145. foreach ($requiredTemplates as $template) {
  146. if (!file_exists($templateDir . $template)) {
  147. return false;
  148. }
  149. }
  150. return true;
  151. });
  152. test("Documentation Files", function() {
  153. $requiredFiles = [
  154. 'README.md',
  155. 'LICENSE',
  156. 'composer.json'
  157. ];
  158. $rootDir = __DIR__ . '/../';
  159. foreach ($requiredFiles as $file) {
  160. if (!file_exists($rootDir . $file)) {
  161. return false;
  162. }
  163. }
  164. return true;
  165. });
  166. echo "\n" . str_repeat("=", 60) . "\n";
  167. echo "📊 Test Results Summary\n";
  168. echo str_repeat("=", 60) . "\n";
  169. echo "✅ Passed: {$passed}\n";
  170. echo "❌ Failed: {$failed}\n";
  171. if ($failed === 0) {
  172. echo "📈 Success Rate: 100%\n";
  173. echo "\n🎉 All basic tests passed! The SixShop Maker Bundle is working correctly.\n";
  174. } else {
  175. echo "📈 Success Rate: " . round(($passed / ($passed + $failed)) * 100, 1) . "%\n";
  176. echo "\n⚠️ Some tests failed. Please review the functionality.\n";
  177. }
  178. echo "\n💡 Manual Testing Commands:\n";
  179. echo "- Extension generation: php bin/sixshop-maker\n";
  180. echo "- Migration generation: php bin/sixshop-maker create_migration\n";
  181. echo "- Help: php bin/sixshop-maker --help\n";
  182. echo "- List commands: php bin/sixshop-maker list\n";
  183. // Cleanup
  184. cleanupTestDir();
  185. echo "\n🧹 Test cleanup completed.\n";