本文整理汇总了PHP中Codeception\Util\Stub::construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Stub::construct方法的具体用法?PHP Stub::construct怎么用?PHP Stub::construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Codeception\Util\Stub
的用法示例。
在下文中一共展示了Stub::construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: constructDumbLicensedComponent
public function constructDumbLicensedComponent($params = array(), $override = array())
{
$defaultParams = array('namespace' => 'DumbExtension', 'type' => 'component');
$defaultOverride = array('getManifestPath' => $this->getExtensionMockPath('com_dumbextension') . '/dumbextension.xml');
$instance = Stub::construct('\\Alledia\\Framework\\Joomla\\Extension\\Licensed', array_merge($defaultParams, $params), array_merge($defaultOverride, $override));
return $instance;
}
示例2: constructDumbGenericCLI
public function constructDumbGenericCLI($params = array(), $override = array())
{
$defaultParams = array('namespace' => 'DumbExtension', 'type' => 'cli');
$defaultOverride = array();
$instance = Stub::construct('\\Alledia\\Framework\\Joomla\\Extension\\Generic', array_merge($defaultParams, $params), array_merge($defaultOverride, $override));
return $instance;
}
示例3: makeCommand
protected function makeCommand($className, $saved = true, $extraMethods = [])
{
if (!$this->config) {
$this->config = [];
}
$self = $this;
$mockedMethods = ['save' => function ($file, $output) use($self, $saved) {
if (!$saved) {
return false;
}
$self->filename = $file;
$self->content = $output;
$self->log[] = ['filename' => $file, 'content' => $output];
$self->saved[$file] = $output;
return true;
}, 'getGlobalConfig' => function () use($self) {
return $self->config;
}, 'getSuiteConfig' => function () use($self) {
return $self->config;
}, 'buildPath' => function ($path, $testName) {
$path = rtrim($path, DIRECTORY_SEPARATOR);
$testName = str_replace(['/', '\\'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $testName);
return pathinfo($path . DIRECTORY_SEPARATOR . $testName, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR;
}, 'getSuites' => function () {
return ['shire'];
}, 'getApplication' => function () {
return new \Codeception\Util\Maybe();
}];
$mockedMethods = array_merge($mockedMethods, $extraMethods);
$this->command = Stub::construct($className, [$this->commandName], $mockedMethods);
}
示例4: _before
public function _before()
{
//echo "ENV:".getenv('thisTestRun_testIncludePath');
//die();
//chdir(getenv('thisTestRun_testIncludePath'));
//require_once "system/classes/Config.php";
$this->config = Stub::construct('Config');
}
示例5: testDelete
public function testDelete()
{
$file = Stub::construct('\\Uploads\\models\\UploadedFile', ['filePath' => $this->baseTestFileString], ['getOwnerClass' => 'Test', 'getOwnerId' => 2, 'getDirToUpload' => yii::getAlias(implode(DIRECTORY_SEPARATOR, ['@backend', 'web', 'upload']))]);
$file->save();
$filePath = $file->fullPath;
$file->delete();
$this->assertFalse(file_exists($filePath));
}
示例6: testCreateSnapshotOnFail
public function testCreateSnapshotOnFail()
{
$module = Stub::construct(get_class($this->module), [make_container()], ['_savePageSource' => Stub::once(function ($filename) {
$this->assertEquals(codecept_log_dir('Codeception.Module.UniversalFramework.looks.like..test.fail.html'), $filename);
})]);
$module->amOnPage('/');
$cest = new \Codeception\Test\Cest($this->module, 'looks:like::test', 'demo1Cest.php');
$module->_failed($cest, new PHPUnit_Framework_AssertionFailedError());
}
示例7: testInstanceLimit
public function testInstanceLimit()
{
$object = Stub::construct('\\WPDemo\\Generator', array(), array('getConfig' => function () {
$config = new \WPDemo\Config();
$config->limit = 0;
return $config;
}));
\PHPUnit_Framework_TestCase::setExpectedException('\\Exception');
$object->instantiateSession();
}
示例8: doRequest
/**
* Makes a request.
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
* @throws \RuntimeException
*/
public function doRequest($request)
{
$application = $this->getApplication();
$di = $application->getDI();
Di::reset();
Di::setDefault($di);
$_SERVER = [];
foreach ($request->getServer() as $key => $value) {
$_SERVER[strtoupper(str_replace('-', '_', $key))] = $value;
}
if (!$application instanceof Application && !$application instanceof MicroApplication) {
throw new RuntimeException('Unsupported application class.');
}
$_COOKIE = $request->getCookies();
$_FILES = $this->remapFiles($request->getFiles());
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_REQUEST = $this->remapRequestParameters($request->getParameters());
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$_GET = $_REQUEST;
} else {
$_POST = $_REQUEST;
}
$uri = str_replace('http://localhost', '', $request->getUri());
$_SERVER['REQUEST_URI'] = $uri;
$_GET['_url'] = strtok($uri, '?');
$_SERVER['QUERY_STRING'] = http_build_query($_GET);
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$di['request'] = Stub::construct($di->get('request'), [], ['getRawBody' => $request->getContent()]);
$response = $application->handle();
$headers = $response->getHeaders();
$status = (int) $headers->get('Status');
$headersProperty = new ReflectionProperty($headers, '_headers');
$headersProperty->setAccessible(true);
$headers = $headersProperty->getValue($headers);
if (!is_array($headers)) {
$headers = [];
}
$cookiesProperty = new ReflectionProperty($di['cookies'], '_cookies');
$cookiesProperty->setAccessible(true);
$cookies = $cookiesProperty->getValue($di['cookies']);
if (is_array($cookies)) {
$restoredProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_restored');
$restoredProperty->setAccessible(true);
$valueProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_value');
$valueProperty->setAccessible(true);
foreach ($cookies as $name => $cookie) {
if (!$restoredProperty->getValue($cookie)) {
$clientCookie = new Cookie($name, $valueProperty->getValue($cookie), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
$headers['Set-Cookie'][] = (string) $clientCookie;
}
}
}
return new Response($response->getContent(), $status ? $status : 200, $headers);
}
示例9: makeCommand
protected function makeCommand($className)
{
$this->config = array();
$self = $this;
$this->command = Stub::construct($className, array($this->commandName), array('save' => function ($file, $output) use($self) {
$self->filename = str_replace(DIRECTORY_SEPARATOR, '/', $file);
$self->content = $output;
$self->log[] = array('filename' => $file, 'content' => $output);
return true;
}, 'getGlobalConfig' => function () use($self) {
return $self->config;
}, 'getSuiteConfig' => function () use($self) {
return $self->config;
}, 'buildPath' => function ($path, $testName) {
$path = rtrim($path, DIRECTORY_SEPARATOR);
$testName = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $testName);
return pathinfo($path . DIRECTORY_SEPARATOR . $testName, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR;
}, 'getSuites' => function () {
return array('shire');
}, 'getApplication' => function () {
return new \Codeception\Util\Maybe();
}));
}
示例10: getInfoAfterConstructForPlugin
public function getInfoAfterConstructForPlugin(UnitTester $I)
{
$I->addExtensionToDatabase('DumbExtension', 'plugin', 'dumbextension', 'system');
$instance = Stub::construct('\\Alledia\\Framework\\Joomla\\Extension\\Generic', array('namespace' => 'DumbExtension', 'type' => 'plugin', 'folder' => 'system'), array('getManifestPath' => $I->getExtensionMockPath('plg_system_dumbextension') . '/dumbextension.xml'));
$type = $I->getAttributeFromInstance($instance, 'type');
$element = $I->getAttributeFromInstance($instance, 'element');
$folder = $I->getAttributeFromInstance($instance, 'folder');
$basePath = $I->getAttributeFromInstance($instance, 'basePath');
$namespace = $I->getAttributeFromInstance($instance, 'namespace');
$id = $I->getAttributeFromInstance($instance, 'id');
$name = $I->getAttributeFromInstance($instance, 'name');
$enabled = $I->getAttributeFromInstance($instance, 'enabled');
$params = $I->getAttributeFromInstance($instance, 'params');
$I->assertEquals('plugin', $type);
$I->assertEquals('dumbextension', $element);
$I->assertEquals('system', $folder);
$I->assertEquals(JPATH_SITE, $basePath);
$I->assertEquals('DumbExtension', $namespace);
$I->assertGreaterThan(0, $id);
$I->assertEquals('DumbExtension', $name);
$I->assertTrue($enabled);
$I->assertClassName('Joomla\\Registry\\Registry', $params);
}
示例11: testStubsFromObject
public function testStubsFromObject()
{
$dummy = Stub::make(new \DummyClass());
$this->assertTrue(isset($dummy->__mocked));
$dummy = Stub::makeEmpty(new \DummyClass());
$this->assertTrue(isset($dummy->__mocked));
$dummy = Stub::makeEmptyExcept(new \DummyClass(), 'helloWorld');
$this->assertTrue(isset($dummy->__mocked));
$dummy = Stub::construct(new \DummyClass());
$this->assertTrue(isset($dummy->__mocked));
$dummy = Stub::constructEmpty(new \DummyClass());
$this->assertTrue(isset($dummy->__mocked));
$dummy = Stub::constructEmptyExcept(new \DummyClass(), 'helloWorld');
$this->assertTrue(isset($dummy->__mocked));
}
示例12: testCanIgnoreTest
public function testCanIgnoreTest()
{
$this->specify('testcase should be ignored if @ignoreProfiler class annotation met', function ($config, $options, $testCaseClass, $testCaseName, $timeout, $annotations, $expectedOutput) {
$profiler = new Profiler($config, $options);
$outputData = '';
$output = Stub::construct('\\Codeception\\Lib\\Console\\Output', [$options], ['write' => Stub::atLeastOnce(function ($messages) use(&$outputData) {
$outputData .= $messages;
})]);
$this->tester->setProtectedProperty($profiler, 'output', $output);
$this->eventsManager->addSubscriber($profiler);
/** @var \PHPUnit_Framework_TestResult $testResult */
$testResult = Stub::makeEmpty('\\PHPUnit_Framework_TestResult');
/** @var \PHPUnit_Util_Printer $printer */
$printer = Stub::makeEmpty('\\PHPUnit_Util_Printer');
$testCase = $this->getMockBuilder('\\Codeception\\TestCase\\Test')->setMethods(['getAnnotations'])->setMockClassName($testCaseClass)->getMock();
$testCase->expects($this->exactly(2))->method('getAnnotations')->will($this->returnValue($annotations));
/** @var Test $testCase */
$testCase->setName($testCaseName);
$this->eventsManager->dispatch(Events::TEST_BEFORE, new TestEvent($testCase));
usleep($timeout * 1000000.0);
$this->eventsManager->dispatch(Events::TEST_END, new TestEvent($testCase));
$this->eventsManager->dispatch(Events::RESULT_PRINT_AFTER, new PrintResultEvent($testResult, $printer));
$this->assertProfileOutput($expectedOutput, $outputData);
}, ['examples' => $this->getTestIgnoreAnnotationsData()]);
}
示例13: testRun
/**
* @param int $exitCode
* @param array $options
* @param bool $withJar
* @param string $expectedStdOutput
*
* @dataProvider casesRun
*/
public function testRun($exitCode, $options, $withJar, $expectedStdOutput)
{
$container = \Robo\Robo::createDefaultContainer();
\Robo\Robo::setContainer($container);
$mainStdOutput = new \Helper\Dummy\Output();
$options += ['workingDirectory' => '.', 'assetJarMapping' => ['report' => ['phpcsLintRun', 'report']], 'reports' => ['json' => null]];
/** @var \Cheppers\Robo\Phpcs\Task\PhpcsLintFiles $task */
$task = Stub::construct(PhpcsLintFiles::class, [$options, []], ['processClass' => \Helper\Dummy\Process::class, 'phpCodeSnifferCliClass' => \Helper\Dummy\PHP_CodeSniffer_CLI::class]);
$processIndex = count(\Helper\Dummy\Process::$instances);
\Helper\Dummy\Process::$prophecy[$processIndex] = ['exitCode' => $exitCode, 'stdOutput' => $expectedStdOutput];
\Helper\Dummy\PHP_CodeSniffer_CLI::$numOfErrors = $exitCode ? 42 : 0;
\Helper\Dummy\PHP_CodeSniffer_CLI::$stdOutput = $expectedStdOutput;
$task->setLogger($container->get('logger'));
$task->setOutput($mainStdOutput);
$assetJar = null;
if ($withJar) {
$assetJar = new AssetJar();
$task->setAssetJar($assetJar);
}
$result = $task->run();
$this->tester->assertEquals($exitCode, $result->getExitCode(), 'Exit code is different than the expected.');
$this->tester->assertEquals($options['workingDirectory'], \Helper\Dummy\Process::$instances[$processIndex]->getWorkingDirectory());
if ($withJar) {
/** @var \Cheppers\LintReport\ReportWrapperInterface $reportWrapper */
$reportWrapper = $assetJar->getValue(['phpcsLintRun', 'report']);
$this->tester->assertEquals(json_decode($expectedStdOutput, true), $reportWrapper->getReport(), 'Output equals');
} else {
$this->tester->assertContains($expectedStdOutput, $mainStdOutput->output, 'Output contains');
}
}
示例14: doRequest
/**
* Makes a request.
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
* @throws \RuntimeException
*/
public function doRequest($request)
{
$application = $this->getApplication();
if (!$application instanceof Application && !$application instanceof MicroApplication) {
throw new RuntimeException('Unsupported application class.');
}
$di = $application->getDI();
/** @var \Phalcon\Http\Request $phRequest */
if ($di->has('request')) {
$phRequest = $di->get('request');
}
if (!$phRequest instanceof RequestInterface) {
$phRequest = new Request();
}
$uri = $request->getUri() ?: $phRequest->getURI();
$pathString = parse_url($uri, PHP_URL_PATH);
$queryString = parse_url($uri, PHP_URL_QUERY);
$_SERVER = $request->getServer();
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = null === $queryString ? $pathString : $pathString . '?' . $queryString;
$_COOKIE = $request->getCookies();
$_FILES = $this->remapFiles($request->getFiles());
$_REQUEST = $this->remapRequestParameters($request->getParameters());
$_POST = [];
$_GET = [];
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$_GET = $_REQUEST;
} else {
$_POST = $_REQUEST;
}
parse_str($queryString, $output);
foreach ($output as $k => $v) {
$_GET[$k] = $v;
}
$_GET['_url'] = $pathString;
$_SERVER['QUERY_STRING'] = http_build_query($_GET);
Di::reset();
Di::setDefault($di);
$di['request'] = Stub::construct($phRequest, [], ['getRawBody' => $request->getContent()]);
$response = $application->handle();
$headers = $response->getHeaders();
$status = (int) $headers->get('Status');
$headersProperty = new ReflectionProperty($headers, '_headers');
$headersProperty->setAccessible(true);
$headers = $headersProperty->getValue($headers);
if (!is_array($headers)) {
$headers = [];
}
$cookiesProperty = new ReflectionProperty($di['cookies'], '_cookies');
$cookiesProperty->setAccessible(true);
$cookies = $cookiesProperty->getValue($di['cookies']);
if (is_array($cookies)) {
$restoredProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_restored');
$restoredProperty->setAccessible(true);
$valueProperty = new ReflectionProperty('\\Phalcon\\Http\\Cookie', '_value');
$valueProperty->setAccessible(true);
foreach ($cookies as $name => $cookie) {
if (!$restoredProperty->getValue($cookie)) {
$clientCookie = new Cookie($name, $valueProperty->getValue($cookie), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
$headers['Set-Cookie'][] = (string) $clientCookie;
}
}
}
return new Response($response->getContent(), $status ? $status : 200, $headers);
}
示例15: testUpdate
public function testUpdate()
{
$dummy = Stub::construct('DummyClass');
Stub::update($dummy, array('checkMe' => 'done'));
$this->assertEquals('done', $dummy->getCheckMe());
}