simple_post_test.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Script simple pour tester POST_userV2.php
  4. */
  5. echo "🚀 Test POST_userV2.php\n\n";
  6. // Charger nos données
  7. $json_file = __DIR__ . '/post_user_request.json';
  8. $post_data = json_decode(file_get_contents($json_file), true);
  9. // Générer un nouveau login unique
  10. $timestamp = time();
  11. $post_data['login'] = "test.user.{$timestamp}@sipa-automobiles.fr";
  12. $post_data['mail'] = $post_data['login'];
  13. $post_data['employeeNumber'] = "TEST{$timestamp}";
  14. $post_data['dtContractStart'] = date('Y-m-d\TH:i:s', strtotime('+1 day'));
  15. $post_data['seniorityDate'] = $post_data['dtContractStart'];
  16. echo "📋 Données:\n";
  17. print_r($post_data);
  18. echo "\n";
  19. // Modifier POST_userV2.php temporairement
  20. $script_path = __DIR__ . '/../api/user/user/POST_userV2.php';
  21. $content = file_get_contents($script_path);
  22. // Activer USE_TEST_DATA et remplacer les données
  23. $content = str_replace(
  24. "define('USE_TEST_DATA', false);",
  25. "define('USE_TEST_DATA', true);",
  26. $content
  27. );
  28. // Remplacer les données de test
  29. $old_test_data = '$input = [
  30. // Champs REQUIS (non-nullable)
  31. "firstName" => "John",';
  32. $new_test_data = '$input = ' . var_export($post_data, true) . ';';
  33. $pos = strpos($content, $old_test_data);
  34. if ($pos !== false) {
  35. $end_pos = strpos($content, '];', $pos);
  36. if ($end_pos !== false) {
  37. $content = substr_replace($content, $new_test_data, $pos, $end_pos - $pos + 2);
  38. }
  39. }
  40. // Sauvegarder temporairement
  41. $temp_script = sys_get_temp_dir() . '/POST_userV2_test_' . $timestamp . '.php';
  42. file_put_contents($temp_script, $content);
  43. echo "📡 Exécution...\n\n";
  44. // Capturer la sortie
  45. ob_start();
  46. include $temp_script;
  47. $output = ob_get_clean();
  48. echo $output;
  49. // Nettoyer
  50. unlink($temp_script);