예제 #1
0
 /**
  * Test environment from mock data
  */
 public function testEnvironmentFromMockData()
 {
     $env = new \Slim\Environment();
     $env->mock(array('SCRIPT_NAME' => '/foo/bar/index.php', 'REQUEST_URI' => '/foo/bar?abc=123'));
     $this->assertInstanceOf('\\Slim\\Interfaces\\EnvironmentInterface', $env);
     $this->assertEquals($env->get('SCRIPT_NAME'), '/foo/bar/index.php');
     $this->assertEquals($env->get('REQUEST_URI'), '/foo/bar?abc=123');
 }
예제 #2
0
파일: AppTest.php 프로젝트: fobiaweb/slim
 protected function createApp(array $envSettings = array(), array $appSettings = array())
 {
     $envSettings = array_merge(array('SCRIPT_NAME' => '/foo/index.php', 'REQUEST_URI' => '/foo/bar?one=foo&two=bar', 'QUERY_STRING' => 'one=foo&two=bar', 'SERVER_NAME' => 'slimframework.com'), $envSettings);
     $appSettings = array_merge(array(), $appSettings);
     $app = new \Slim\App($appSettings);
     $app['environment'] = function () use($envSettings) {
         $env = new \Slim\Environment();
         $env->mock($envSettings);
         return $env;
     };
     return $app;
 }
 public function testCreateEntity()
 {
     $controller = new JsonApiController();
     $object = new NwApi\Entities\User();
     $object->name = $this->faker->userName();
     $object->twitterId = $this->faker->randomDigit();
     Slim\Environment::mock(['HTTP_CONTENT_TYPE' => 'application/json', 'slim.input' => json_encode($object)]);
     $di = Di::getInstance();
     $di->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $di->jsonApiRouter = $this->getMockBuilder('NwApi\\Libraries\\RestDoctrineRouter')->disableOriginalConstructor()->getMock();
     $meta = $this->getMockBuilder("Doctrine\\ORM\\Mapping\\ClassMetadata")->setConstructorArgs([get_class($object)])->getMock();
     $meta->expects($this->any())->method('hasField')->willReturn(true);
     $meta->expects($this->any())->method('isIdentifier')->willReturn(false);
     $controller->createEntity($meta);
 }
예제 #4
0
<?php

use League\CLImate\CLImate;
// Generate the pathinfo by getting the first argument of the script
array_shift($argv);
// Discard the filename
$pathinfo = array_shift($argv);
if (empty($pathinfo)) {
    $pathinfo = '--help';
}
// Create our app instance
$app = new SlimController\Slim(['debug' => false, 'controller.class_prefix' => '', 'controller.class_suffix' => '', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => '']);
// Set up the environment so that Slim can route
$app->environment = Slim\Environment::mock(['PATH_INFO' => $pathinfo]);
// Define the help command. If it doesn't have a name it won't include itself
$app->get('--help', function () use($app) {
    $writer = new CLImate();
    $writer->bold()->out('Available commands:');
    foreach ($app->router()->getNamedRoutes() as $route) {
        $writer->green()->out('    ' . $route->getPattern());
    }
});
// CLI-compatible not found error handler
$app->notFound(function () use($app) {
    $writer = new CLImate();
    $command = $app->environment['PATH_INFO'];
    $writer->red()->bold()->out(sprintf('Error: Cannot route to command "%s"', $command));
    $helpRoute = $app->router()->getMatchedRoutes('GET', '--help', true);
    $helpRoute[0]->dispatch();
    $app->stop();
});
예제 #5
0
 public function testDoesNotUseCertainHeaders()
 {
     $env = new \Slim\Environment();
     $env->mock(array('CONTENT_TYPE' => 'text/csv', 'HTTP_CONTENT_TYPE' => 'text/plain', 'CONTENT_LENGTH' => 10, 'HTTP_CONTENT_LENGTH' => 20));
     $headers = new \Slim\Http\Headers($env);
     $this->assertEquals('text/csv', $headers->get('HTTP_CONTENT_TYPE'));
     $this->assertEquals(10, $headers->get('HTTP_CONTENT_LENGTH'));
 }