Repository navigation
Expand file tree
/
Copy pathSilex.php
More file actions
100 lines (90 loc) · 2.49 KB
/
Copy pathSilex.php
File metadata and controls
100 lines (90 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Codeception\Module;
use Codeception\Configuration;
use Codeception\Exception\ModuleConfigException;
use Codeception\Lib\Framework;
use Codeception\Lib\Interfaces\SupportsDomainRouting;
use Codeception\TestCase;
use Symfony\Component\HttpKernel\Client;
/**
* Module for testing Silex applications like you would regularly do with Silex\WebTestCase.
* This module uses Symfony2 Crawler and HttpKernel to emulate requests and get response.
*
* This module may be considered experimental and require feedback and pull requests from you )
*
* ## Status
*
* * Maintainer: **davert**
* * Stability: **alpha**
* * Contact: davert.codecept@resend.cc
*
* ## Config
*
* * app: **required** - path to Silex bootstrap file.
*
* ### Bootstrap File
*
* Bootstrap is the same as [WebTestCase.createApplication](http://silex.sensiolabs.org/doc/testing.html#webtestcase) should be.
*
* ``` php
* <?
* $app = require __DIR__.'/path/to/app.php';
* $app['debug'] = true;
* $app['exception_handler']->disable();
*
* return $app; // optionally
* ?>
* ```
*
* ### Example (`functional.suite.yml`)
*
* modules:
* enabled:
* - Silex:
* app: 'app/bootstrap.php'
*
* Class Silex
* @package Codeception\Module
*/
class Silex extends Framework implements SupportsDomainRouting
{
protected $app;
protected $requiredFields = ['app'];
public function _initialize()
{
if (!file_exists(Configuration::projectDir() . $this->config['app'])) {
throw new ModuleConfigException(__CLASS__, "Bootstrap file {$this->config['app']} not found");
}
}
public function _before(TestCase $test)
{
$this->app = require Configuration::projectDir() . $this->config['app'];
// if $app is not returned but exists
if (isset($app)) {
$this->app = $app;
}
if (!isset($this->app)) {
throw new ModuleConfigException(__CLASS__, "\$app instance was not received from bootstrap file");
}
// some silex apps (like bolt) may rely on global $app variable
$GLOBALS['app'] = $this->app;
$this->client = new Client($this->app);
}
/**
* Return an instance of a class from the Container.
*
* Example
* ``` php
* <?php
* $I->grabService('session');
* ?>
* ```
*
* @param string $service
* @return mixed
*/
public function grabService($service)
{
return $this->app[$service];
}
}