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;
 }
 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;
 }
 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);
 }
Esempio n. 4
0
 public function _before()
 {
     //echo "ENV:".getenv('thisTestRun_testIncludePath');
     //die();
     //chdir(getenv('thisTestRun_testIncludePath'));
     //require_once "system/classes/Config.php";
     $this->config = Stub::construct('Config');
 }
Esempio n. 5
0
 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));
 }
 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());
 }
Esempio n. 7
0
 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();
 }
Esempio n. 8
0
 /**
  * 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);
 }
Esempio n. 9
0
 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();
     }));
 }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 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));
 }
 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()]);
 }
Esempio n. 13
0
 /**
  * @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');
     }
 }
Esempio n. 14
0
 /**
  * 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);
 }
Esempio n. 15
0
 public function testUpdate()
 {
     $dummy = Stub::construct('DummyClass');
     Stub::update($dummy, array('checkMe' => 'done'));
     $this->assertEquals('done', $dummy->getCheckMe());
 }
Esempio n. 16
0
 public function testRunNativeAndExtraReporterConflict()
 {
     $container = \Robo\Robo::createDefaultContainer();
     \Robo\Robo::setContainer($container);
     $options = ['format' => 'stylish', 'lintReporters' => ['aKey' => new VerboseReporter()]];
     /** @var Task $task */
     $task = Stub::construct(Task::class, [$options, []], ['container' => $container]);
     $task->setLogger($container->get('logger'));
     $assetJar = new \Cheppers\AssetJar\AssetJar();
     $task->setAssetJar($assetJar);
     $result = $task->run();
     $this->assertEquals(3, $result->getExitCode());
     $this->assertEquals('Extra lint reporters can be used only if the output format is "json".', $result->getMessage());
 }
Esempio n. 17
0
 /**
  * @param array $expected
  * @param array $options
  * @param array $properties
  *
  * @dataProvider casesRun
  */
 public function testRun(array $expected, array $options, array $files, array $properties = [])
 {
     $container = \Robo\Robo::createDefaultContainer();
     \Robo\Robo::setContainer($container);
     $mainStdOutput = new \Helper\Dummy\Output();
     $properties += ['processClass' => \Helper\Dummy\Process::class];
     /** @var \Cheppers\Robo\Phpcs\Task\PhpcsLintInput $task */
     $task = Stub::construct(PhpcsLintInput::class, [$options, []], $properties);
     $processIndex = count(\Helper\Dummy\Process::$instances);
     foreach ($files as $file) {
         \Helper\Dummy\Process::$prophecy[$processIndex] = ['exitCode' => $file['lintExitCode'], 'stdOutput' => $file['lintStdOutput']];
         $processIndex++;
     }
     $task->setLogger($container->get('logger'));
     $task->setOutput($mainStdOutput);
     $result = $task->run();
     $this->tester->assertEquals($expected['exitCode'], $result->getExitCode());
     /** @var \Cheppers\LintReport\ReportWrapperInterface $reportWrapper */
     $reportWrapper = $result['report'];
     $this->tester->assertEquals($expected['report'], $reportWrapper->getReport());
 }
Esempio n. 18
0
 public function testStubPrivateProperties()
 {
     $tester = Stub::construct('myClassWithPrivateProperties', ['name' => 'gamma'], ['randomName' => 'chicken', 't' => 'ticky2', 'getRandomName' => function () {
         return "randomstuff";
     }]);
     $this->assertEquals('gamma', $tester->getName());
     $this->assertEquals('randomstuff', $tester->getRandomName());
     $this->assertEquals('ticky2', $tester->getT());
 }
Esempio n. 19
0
 /**
  * @dataProvider matcherProvider
  */
 public function testMethodMatcherWithConstruct($count, $matcher)
 {
     $dummy = Stub::construct('DummyClass', array(), array('goodByeWorld' => $matcher), $this);
     $this->repeatCall($count, array($dummy, 'goodByeWorld'));
 }