A small Slim application for returning a list of pages in a MediaWiki category, ordered by Dale-Chall readability scores.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

  1. <?php
  2. namespace Tests\Functional;
  3. use Slim\App;
  4. use Slim\Http\Request;
  5. use Slim\Http\Response;
  6. use Slim\Http\Environment;
  7. /**
  8. * This is an example class that shows how you could set up a method that
  9. * runs the application. Note that it doesn't cover all use-cases and is
  10. * tuned to the specifics of this skeleton app, so if your needs are
  11. * different, you'll need to change it.
  12. */
  13. class BaseTestCase extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * Use middleware when running application?
  17. *
  18. * @var bool
  19. */
  20. protected $withMiddleware = true;
  21. /**
  22. * Process the application given a request method and URI
  23. *
  24. * @param string $requestMethod the request method (e.g. GET, POST, etc.)
  25. * @param string $requestUri the request URI
  26. * @param array|object|null $requestData the request data
  27. * @return \Slim\Http\Response
  28. */
  29. public function runApp($requestMethod, $requestUri, $requestData = null)
  30. {
  31. // Create a mock environment for testing with
  32. $environment = Environment::mock(
  33. [
  34. 'REQUEST_METHOD' => $requestMethod,
  35. 'REQUEST_URI' => $requestUri
  36. ]
  37. );
  38. // Set up a request object based on the environment
  39. $request = Request::createFromEnvironment($environment);
  40. // Add request data, if it exists
  41. if (isset($requestData)) {
  42. $request = $request->withParsedBody($requestData);
  43. }
  44. // Set up a response object
  45. $response = new Response();
  46. // Use the application settings
  47. $settings = require __DIR__ . '/../../src/settings.php';
  48. // Instantiate the application
  49. $app = new App($settings);
  50. // Set up dependencies
  51. require __DIR__ . '/../../src/dependencies.php';
  52. // Register middleware
  53. if ($this->withMiddleware) {
  54. require __DIR__ . '/../../src/middleware.php';
  55. }
  56. // Register routes
  57. require __DIR__ . '/../../src/routes.php';
  58. // Process the application
  59. $response = $app->process($request, $response);
  60. // Return the response
  61. return $response;
  62. }
  63. }