/** * Test Register Finder * * @param integer $n Umpteenth Number * * @return void * * @dataProvider providerTestUmpteenth */ public function testIntegratorSuccess($n) { $path = realpath(__DIR__ . "/../resources/") . "/"; $oldFinder = new Symfony\Component\Finder\Finder(); $app = new Silex\Application(); $app->register(new \NachoNerd\Silex\Finder\Provider()); $app->boot(); $app['nn.finder']->sortByModifiedTimeDesc()->in($path); $newFinder = $app['nn.finder']->getNFirst($n); $filesNewWay = array(); foreach ($newFinder as $files) { $filesNewWay[] = $files; } $oldFinder->sort(function ($a, $b) { return $b->getMTime() - $a->getMTime(); })->in($path); $filesOldWay = array(); $j = 0; foreach ($oldFinder as $files) { if ($j == $n) { break; } $j++; $filesOldWay[] = $files; } $this->assertEquals($filesOldWay, $filesNewWay); }
public function testCreateSilexApplication() { $logger = new \Psr\Log\NullLogger(); $silex = new Silex\Application(array('debug' => true, 'logger' => $logger)); $silex->register(new \PHPExtra\Proxy\Provider\Silex\ProxyServiceProvider(), array('logger' => $logger, 'proxy.storage' => new \PHPExtra\Proxy\Storage\InMemoryStorage(), 'proxy.adapter.name' => 'dummy', 'proxy.adapter.dummy.handler' => $silex->protect(function (\PHPExtra\Proxy\Http\RequestInterface $request) { return new \PHPExtra\Proxy\Http\Response('I see ' . $request->getRequestUri()); }), 'proxy.logger.access_log' => $logger)); $silex->register(new \PHPExtra\EventManager\Silex\EventManagerServiceProvider()); $silex->boot(); $request = \Symfony\Component\HttpFoundation\Request::create('http://test.com/ping'); $response = $silex->handle($request); $silex->terminate($request, $response); $this->assertEquals('I see /ping', $response->getContent()); $this->assertEquals(200, $response->getStatusCode()); }
protected function createApplication($noTwig = false, $noSm = false) { $app = new \Silex\Application(); $this->mockGenerator->orphanize('__construct'); $sm = new \mock\Swift_Mailer(); $this->calling($sm)->send = function ($message = null) { return $message; }; $app->register(new \Rad\Silex\MailerServiceProvider(), array('rad_mailer.from' => '*****@*****.**')); if (!$noTwig) { $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../../template')); } if (!$noSm) { $app['mailer'] = $sm; } $app->boot(); return $app; }
/** * @return Silex\Application */ static function getApp() { $app = new \Silex\Application(); $app['debug'] = TRUE; $app->register(new MonologServiceProvider(), array('monolog.logfile' => ROOT . '/log.txt')); $app->register(new UrlGeneratorServiceProvider()); $app->register(new ConsoleServiceProvider()); $app->register(new SessionServiceProvider(), array('session.test' => TRUE)); $app->register(new TranslationServiceProvider()); $app->register(new TwigServiceProvider(), array("twig.options" => array("path" => ROOT))); $app->register(new FormServiceProvider()); $app->register(new DoctrineServiceProvider(), array("db.options" => array("driver" => "pdo_sqlite", "path" => 'url_shortener.sqlite'))); $app->register(new DoctrineORMServiceProvider()); $app->register(new UrlShortenerAppServiceProvider()); $app->register(new ValidatorServiceProvider()); /*$app->register(new ValidatorServiceProvider, array( "validator.mapping.chain_loader" => $app->share(function ($app) { return new CustomLoaderChain( array( new StaticMethodLoader, ) ); }), "validator.mapping.class_metadata_factory" => $app->share(function ($app) { return new ClassMetadataFactory($app['validator.chain_loader']); }) ));*/ $app->mount("/", $app['url_shortener.controller']); $app->boot(); /** * create the database */ /* @var $em \Doctrine\ORM\EntityManager */ $em = $app['orm.em']; $app['createDB'] = $app->protect(function () use($em) { $tool = new SchemaTool($em); $tool->dropDatabase(); $tool->createSchema($em->getMetadataFactory()->getAllMetadata()); }); return $app; }
<?php $fileName = __DIR__ . '/../vendor/autoload.php'; if (false === file_exists($fileName)) { $fileName = __DIR__ . '/../../../autoload.php'; } /** @noinspection PhpIncludeInspection */ require_once $fileName; use Cilex\Provider\Console\Adapter\Silex\ConsoleServiceProvider; use Cilex\Provider\Console\ContainerAwareApplication; use Symfony\Component\Finder\Finder; $silex = new Silex\Application(['path.app' => __DIR__, 'path.config' => __DIR__ . '/config', 'path.resources' => __DIR__ . '/resources', 'path.src' => realpath(__DIR__ . '/../src'), 'path.images' => realpath(__DIR__ . '/../images')]); foreach (Finder::create()->in($silex['path.config'])->name('*.yaml') as $file) { $silex->register(new \Igorw\Silex\ConfigServiceProvider((string) $file)); } $silex->register(new ConsoleServiceProvider(), ['console.name' => 'Docplanner Crane', 'console.version' => '1.0.0']); $silex->register(new \Nassau\Silex\Provider\CommandsProvider(), ['commands.path' => $silex['path.src']]); $silex->register(new \Crane\Silex\DockerServiceProvider()); $silex->register(new \Crane\Silex\JsonValidatorProvider()); $silex->register(new \Crane\Silex\ConfigurationServiceProvider()); // since starting a console does not boot Silex $silex->boot(); /** @var ContainerAwareApplication $console */ $console = $silex->offsetGet('console'); $console->run();
<?php /** * Created by PhpStorm. * User: Kessiler * Date: 14/12/2014 * Time: 14:58 */ $app = new Silex\Application(); /** SERVICES */ $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->register(new Silex\Provider\SessionServiceProvider()); $app->register(new Core\Service\ConfigServiceProvider(realpath(__DIR__) . "/../app/config/settings.json")); $app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $app['config']['database'])); $app['debug'] = $app['config']['debugger']; $app->boot(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => realpath(__DIR__) . '/../templates/' . $app['config']['template'], 'twig.options' => array('cache' => $app['config']['cache'] ? realpath(__DIR__) . "/../app/cache" : false, 'strict_variables' => true))); /** ROUTING */ Symfony\Component\HttpFoundation\Request::enableHttpMethodParameterOverride(); require_once realpath(__DIR__) . "/routes.php"; return $app;
/** * Test Boot Finder * * @return void */ public function testBootFinder() { $app = new Silex\Application(); $app->register(new \NachoNerd\Silex\Finder\Provider()); $app->boot(); $this->assertInstanceOf('NachoNerd\\Silex\\Finder\\Extensions\\Finder', $app['nn.finder']); }