execute_post_with_test_mode.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Script pour exécuter POST_userV2.php en mode test
  4. * en modifiant temporairement le fichier pour utiliser nos données
  5. */
  6. echo "🚀 Exécution de POST_userV2.php en mode test...\n\n";
  7. // Charger nos données
  8. $json_file = __DIR__ . '/post_user_request.json';
  9. $post_data = json_decode(file_get_contents($json_file), true);
  10. // Générer un nouveau login unique
  11. $timestamp = time();
  12. $post_data['login'] = "test.user.{$timestamp}@sipa-automobiles.fr";
  13. $post_data['mail'] = $post_data['login'];
  14. $post_data['employeeNumber'] = "TEST{$timestamp}";
  15. $post_data['dtContractStart'] = date('Y-m-d\TH:i:s', strtotime('+1 day'));
  16. $post_data['seniorityDate'] = $post_data['dtContractStart'];
  17. echo "📋 Données de la requête:\n";
  18. echo json_encode($post_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
  19. // Lire le script POST_userV2.php
  20. $script_path = __DIR__ . '/../api/user/user/POST_userV2.php';
  21. $script_content = file_get_contents($script_path);
  22. // Sauvegarder l'original
  23. $backup_path = $script_path . '.backup';
  24. if (!file_exists($backup_path)) {
  25. file_put_contents($backup_path, $script_content);
  26. echo "💾 Backup créé: {$backup_path}\n\n";
  27. }
  28. // Activer USE_TEST_DATA
  29. $script_content = str_replace(
  30. "define('USE_TEST_DATA', false);",
  31. "define('USE_TEST_DATA', true);",
  32. $script_content
  33. );
  34. // Remplacer les données de test
  35. $test_data_pattern = '/if \(USE_TEST_DATA\) \{[^}]*\$input = \[.*?\];/s';
  36. $replacement = "if (USE_TEST_DATA) {\n \$input = " . var_export($post_data, true) . ";";
  37. if (preg_match($test_data_pattern, $script_content)) {
  38. $script_content = preg_replace($test_data_pattern, $replacement, $script_content);
  39. } else {
  40. // Méthode alternative : trouver et remplacer manuellement
  41. $start_pos = strpos($script_content, 'if (USE_TEST_DATA) {');
  42. if ($start_pos !== false) {
  43. $end_pos = strpos($script_content, '}', $start_pos + 50);
  44. if ($end_pos !== false) {
  45. $old_block = substr($script_content, $start_pos, $end_pos - $start_pos + 1);
  46. $new_block = "if (USE_TEST_DATA) {\n \$input = " . var_export($post_data, true) . ";\n}";
  47. $script_content = str_replace($old_block, $new_block, $script_content);
  48. }
  49. }
  50. }
  51. // Sauvegarder temporairement
  52. file_put_contents($script_path, $script_content);
  53. echo "📡 Exécution du script...\n\n";
  54. // Capturer la sortie
  55. ob_start();
  56. include $script_path;
  57. $output = ob_get_clean();
  58. echo $output;
  59. // Restaurer l'original
  60. file_put_contents($script_path, file_get_contents($backup_path));
  61. echo "\n✅ Script restauré à son état original\n";