This commit is contained in:
2020-10-06 14:27:47 +07:00
commit 586be80cf6
16613 changed files with 3274099 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
<?php
use Codeception\Util\Stub;
use Codeception\Application;
use Symfony\Component\Console\Tester\CommandTester;
class BaseCommandRunner extends \PHPUnit\Framework\TestCase
{
/**
* @var \Codeception\Command\Base
*/
protected $command;
public $filename = "";
public $content = "";
public $output = "";
public $config = [];
public $saved = [];
protected $commandName = 'do:stuff';
protected function execute($args = [], $isSuite = true)
{
$app = new Application();
$app->add($this->command);
$default = \Codeception\Configuration::$defaultConfig;
$default['paths']['tests'] = __DIR__;
$conf = $isSuite
? \Codeception\Configuration::suiteSettings('unit', $default)
: $default;
$this->config = array_merge($conf, $this->config);
$commandTester = new CommandTester($app->find($this->commandName));
$args['command'] = $this->commandName;
$commandTester->execute($args, ['interactive' => false]);
$this->output = $commandTester->getDisplay();
}
protected function makeCommand($className, $saved = true, $extraMethods = [])
{
if (!$this->config) {
$this->config = [];
}
$self = $this;
$mockedMethods = [
'createFile' => 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;
},
'createDirectoryFor' => 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
);
}
protected function assertIsValidPhp($php)
{
$temp_file = tempnam(sys_get_temp_dir(), 'CodeceptionUnitTest');
file_put_contents($temp_file, $php);
exec('php -l ' . $temp_file, $output, $code);
unlink($temp_file);
$this->assertEquals(0, $code, $php);
}
}

View File

@@ -0,0 +1,49 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class BuildTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\Build');
$this->config = array(
'actor' => 'HobbitGuy',
'path' => 'tests/shire/',
'modules' => array('enabled' => array('Filesystem', 'EmulateModuleHelper')),
'include' => []
);
}
public function testBuild()
{
$this->execute();
$this->assertContains('class HobbitGuy extends \Codeception\Actor', $this->content);
// inherited methods from Actor
$this->assertContains('@method void wantTo($text)', $this->content);
$this->assertContains('@method void expectTo($prediction)', $this->content);
$this->content = $this->log[0]['content'];
// methods from Filesystem module
$this->assertContains('public function amInPath($path)', $this->content);
$this->assertContains('public function copyDir($src, $dst)', $this->content);
$this->assertContains('public function seeInThisFile($text)', $this->content);
// methods from EmulateHelper
$this->assertContains('public function seeEquals($expected, $actual)', $this->content);
$this->assertContains('HobbitGuyActions.php generated successfully.', $this->output);
$this->assertIsValidPhp($this->content);
}
public function testBuildNamespacedActor()
{
$this->config['namespace'] = 'Shire';
$this->execute();
$this->assertContains('namespace Shire;', $this->content);
$this->assertContains('class HobbitGuy extends \Codeception\Actor', $this->content);
$this->assertContains('use _generated\HobbitGuyActions;', $this->content);
$this->assertIsValidPhp($this->content);
}
}

View File

@@ -0,0 +1,54 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateCeptTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GenerateCept');
$this->config = array(
'actor' => 'HobbitGuy',
'path' => 'tests/shire',
);
}
public function testGenerateBasic()
{
$this->execute(array('suite' => 'shire', 'test' => 'HomeCanInclude12Dwarfs'));
$this->assertEquals($this->filename, 'tests/shire/HomeCanInclude12DwarfsCept.php');
$this->assertContains('$I = new HobbitGuy($scenario);', $this->content);
$this->assertContains('Test was created in tests/shire/HomeCanInclude12DwarfsCept.php', $this->output);
$this->assertIsValidPhp($this->content);
}
public function testGenerateWithSuffix()
{
$this->execute(array('suite' => 'shire', 'test' => 'HomeCanInclude12DwarfsCept'));
$this->assertEquals($this->filename, 'tests/shire/HomeCanInclude12DwarfsCept.php');
$this->assertIsValidPhp($this->content);
}
/**
* @group command
*/
public function testGenerateWithFullName()
{
$this->execute(array('suite' => 'shire', 'test' => 'HomeCanInclude12DwarfsCept.php'));
$this->assertEquals($this->filename, 'tests/shire/HomeCanInclude12DwarfsCept.php');
$this->assertIsValidPhp($this->content);
}
/**
* @group command
*/
public function testGenerateWithGuyNamespaced()
{
$this->config['namespace'] = 'MiddleEarth';
$this->execute(array('suite' => 'shire', 'test' => 'HomeCanInclude12Dwarfs'));
$this->assertEquals($this->filename, 'tests/shire/HomeCanInclude12DwarfsCept.php');
$this->assertContains('use MiddleEarth\HobbitGuy;', $this->content);
$this->assertContains('$I = new HobbitGuy($scenario);', $this->content);
$this->assertIsValidPhp($this->content);
}
}

View File

@@ -0,0 +1,94 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateCestTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GenerateCest');
$this->config = array(
'actor' => 'HobbitGuy',
'path' => 'tests/shire',
);
}
/**
* @group command
*/
public function testBasic()
{
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
$this->assertEquals('tests/shire/HallUnderTheHillCest.php', $this->filename);
$this->assertContains('class HallUnderTheHillCest', $this->content);
$this->assertContains('public function _before(HobbitGuy $I)', $this->content);
$this->assertContains('public function _after(HobbitGuy $I)', $this->content);
$this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
$this->assertContains('Test was created in tests/shire/HallUnderTheHillCest.php', $this->output);
}
/**
* @group command
*/
public function testNamespaced()
{
$this->config['namespace'] = 'Shire';
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
$this->assertContains('namespace Shire;', $this->content);
$this->assertContains('use Shire\HobbitGuy;', $this->content);
$this->assertContains('class HallUnderTheHillCest', $this->content);
}
/**
* @group command
*/
public function testGenerateWithFullName()
{
$this->execute(array('suite' => 'shire', 'class' => 'HomeCanInclude12DwarfsCest.php'));
$this->assertEquals('tests/shire/HomeCanInclude12DwarfsCest.php', $this->filename);
}
/**
* @group command
*/
public function testGenerateWithSuffix()
{
$this->execute(array('suite' => 'shire', 'class' => 'HomeCanInclude12DwarfsCest'));
$this->assertEquals($this->filename, 'tests/shire/HomeCanInclude12DwarfsCest.php');
$this->assertIsValidPhp($this->content);
}
public function testGenerateWithGuyNamespaced()
{
$this->config['namespace'] = 'MiddleEarth';
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillCest'));
$this->assertEquals($this->filename, 'tests/shire/HallUnderTheHillCest.php');
$this->assertContains('namespace MiddleEarth;', $this->content);
$this->assertContains('use MiddleEarth\\HobbitGuy;', $this->content);
$this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
$this->assertIsValidPhp($this->content);
}
public function testCreateWithNamespace()
{
$this->execute(array('suite' => 'shire', 'class' => 'MiddleEarth\HallUnderTheHillCest'));
$this->assertEquals('tests/shire/MiddleEarth/HallUnderTheHillCest.php', $this->filename);
$this->assertContains('namespace MiddleEarth;', $this->content);
$this->assertContains('class HallUnderTheHillCest', $this->content);
$this->assertContains('Test was created in tests/shire/MiddleEarth/HallUnderTheHillCest.php', $this->output);
}
public function testGenerateWithSuiteNamespace()
{
$this->config['suite_namespace'] = 'MiddleEarth\\Bosses\\';
$this->config['namespace'] = 'MiddleEarth';
$this->config['actor'] = 'HobbitGuy';
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillCest'));
$this->assertEquals($this->filename, 'tests/shire/HallUnderTheHillCest.php');
$this->assertContains('namespace MiddleEarth\\Bosses;', $this->content);
$this->assertContains('use MiddleEarth\\HobbitGuy', $this->content);
$this->assertContains('public function tryToTest(HobbitGuy $I)', $this->content);
$this->assertIsValidPhp($this->content);
}
}

View File

@@ -0,0 +1,30 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateEnvironmentTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GenerateEnvironment');
$this->config = [
'class_name' => 'HobbitGuy',
'path' => 'tests/shire',
'paths' => ['envs' => 'tests/_envs','tests' => 'tests'],
];
}
public function testCreated()
{
$this->execute(['env' => 'firefox']);
$this->assertContains('firefox config was created in tests/_envs/firefox.yml', $this->output);
$this->assertEquals('tests/_envs/firefox.yml', $this->filename);
}
public function testFailed()
{
$this->makeCommand('\Codeception\Command\GenerateEnvironment', false);
$this->execute(['env' => 'firefox']);
$this->assertContains('File tests/_envs/firefox.yml already exists', $this->output);
}
}

View File

@@ -0,0 +1,42 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateGroupTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GenerateGroup');
$this->config = array(
'class_name' => 'HobbitGuy',
'path' => 'tests/shire',
'paths' => array('support' => 'tests/_support','tests' => 'tests'),
'settings' => array('bootstrap' => '_bootstrap.php')
);
}
public function testBasic()
{
$this->execute(array('group' => 'Core'));
$generated = $this->log[0];
$this->assertEquals(\Codeception\Configuration::supportDir().'Group/Core.php', $generated['filename']);
$this->assertContains('namespace Group;', $generated['content']);
$this->assertContains('class Core', $generated['content']);
$this->assertContains('public function _before', $generated['content']);
$this->assertContains('public function _after', $generated['content']);
$this->assertContains('static $group = \'core\'', $generated['content']);
$this->assertIsValidPhp($generated['content']);
}
public function testNamespace()
{
$this->config['namespace'] = 'Shire';
$this->execute(array('group' => 'Core'));
$generated = $this->log[0];
$this->assertEquals(\Codeception\Configuration::supportDir().'Group/Core.php', $generated['filename']);
$this->assertContains('namespace Shire\Group;', $generated['content']);
$this->assertIsValidPhp($generated['content']);
}
}

View File

@@ -0,0 +1,70 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GeneratePageObjectTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GeneratePageObject');
$this->config = array(
'actor' => 'HobbitGuy',
'path' => 'tests/shire',
'paths' => array('tests' => 'tests'),
'settings' => array('bootstrap' => '_bootstrap.php')
);
}
public function testBasic()
{
unset($this->config['actor']);
$this->execute(array('suite' => 'Login'), false);
$this->assertEquals(\Codeception\Configuration::supportDir().'Page/Login.php', $this->filename);
$this->assertContains('class Login', $this->content);
$this->assertContains('public static', $this->content);
$this->assertNotContains('public function __construct', $this->content);
$this->assertIsValidPhp($this->content);
}
public function testNamespace()
{
unset($this->config['actor']);
$this->config['namespace'] = 'MiddleEarth';
$this->execute(array('suite' => 'Login'), false);
$this->assertEquals(\Codeception\Configuration::supportDir().'Page/Login.php', $this->filename);
$this->assertContains('namespace MiddleEarth\Page;', $this->content);
$this->assertContains('class Login', $this->content);
$this->assertContains('public static', $this->content);
$this->assertIsValidPhp($this->content);
}
public function testCreateForSuite()
{
$this->execute(array('suite' => 'shire', 'page' => 'Login'));
$this->assertEquals(\Codeception\Configuration::supportDir().'Page/Shire/Login.php', $this->filename);
$this->assertContains('namespace Page\Shire;', $this->content);
$this->assertContains('class Login', $this->content);
$this->assertContains('protected $hobbitGuy;', $this->content);
$this->assertContains('public function __construct(\HobbitGuy $I)', $this->content);
$this->assertIsValidPhp($this->content);
}
public function testCreateForSuiteWithNamespace()
{
$this->config['namespace'] = 'MiddleEarth';
$this->execute(array('suite' => 'shire', 'page' => 'Login'));
$this->assertEquals(\Codeception\Configuration::supportDir().'Page/Shire/Login.php', $this->filename);
$this->assertContains('namespace MiddleEarth\Page\Shire;', $this->content);
$this->assertContains('class Login', $this->content);
$this->assertContains('protected $hobbitGuy;', $this->content);
$this->assertContains('public function __construct(\MiddleEarth\HobbitGuy $I)', $this->content);
$this->assertIsValidPhp($this->content);
}
public function testCreateInSubpath()
{
$this->execute(array('suite' => 'User/View'));
$this->assertEquals(\Codeception\Configuration::supportDir().'Page/User/View.php', $this->filename);
$this->assertIsValidPhp($this->content);
}
}

View File

@@ -0,0 +1,107 @@
<?php
use Codeception\Lib\ModuleContainer;
use Codeception\Util\Stub;
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateScenarioTest extends BaseCommandRunner
{
/**
* @var ModuleContainer
*/
protected $moduleContainer;
protected function setUp()
{
$this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), []);
$this->moduleContainer->create('EmulateModuleHelper');
$this->modules = $this->moduleContainer->all();
$this->actions = $this->moduleContainer->getActions();
$this->filename = null;
$this->makeCommand('\Codeception\Command\GenerateScenarios');
$this->config = array(
'paths' => array(
'tests' => 'tests/data/claypit/tests/',
'data' => '_data',
),
'class_name' => 'DumbGuy',
'path' => 'tests/data/claypit/tests/dummy/'
);
}
public function testBasic()
{
$this->execute(array('suite' => 'dummy'));
$file = codecept_root_dir().'tests/data/scenarios/dummy/File_Exists.txt';
$this->assertArrayHasKey($file, $this->saved);
$content = $this->saved[$file];
$this->assertContains('I WANT TO CHECK CONFIG EXISTS', $content);
$this->assertContains('I see file found "$codeception"', $content);
$this->assertContains('* File_Exists generated', $this->output);
}
public function testMultipleTestsGeneration()
{
$this->execute(['suite' => 'dummy']);
$this->assertArrayHasKey(codecept_root_dir().'tests/data/scenarios/dummy/Another.optimistic.txt', $this->saved);
$this->assertArrayHasKey(codecept_root_dir().'tests/data/scenarios/dummy/Another.pessimistic.txt', $this->saved);
$file = codecept_root_dir().'tests/data/scenarios/dummy/File_Exists.txt';
$this->assertArrayHasKey($file, $this->saved);
$content = $this->saved[$file];
$this->assertContains('I WANT TO CHECK CONFIG EXISTS', $content);
$this->assertContains('I see file found "$codeception"', $content);
$this->assertContains('* File_Exists generated', $this->output);
}
public function testHtml()
{
$this->execute(array('suite' => 'dummy', '--format' => 'html'));
$file = codecept_root_dir().'tests/data/scenarios/dummy/File_Exists.html';
$this->assertArrayHasKey($file, $this->saved);
$content = $this->saved[$file];
$this->assertContains('<html><body><h3>I WANT TO CHECK CONFIG EXISTS</h3>', $content);
$this->assertContains('I see file found &quot;$codeception&quot;', strip_tags($content));
$this->assertContains('* File_Exists generated', $this->output);
}
public function testOneFile()
{
$this->config['path'] = 'tests/data/claypit/tests/skipped/';
$this->config['class_name'] = 'SkipGuy';
$this->execute(array('suite' => 'skipped', '--single-file' => true));
$this->assertEquals(codecept_root_dir().'tests/data/scenarios/skipped.txt', $this->filename);
$this->assertContains('I WANT TO SKIP IT', $this->content);
$this->assertContains('I WANT TO MAKE IT INCOMPLETE', $this->content);
$this->assertContains('* Skip_Me rendered', $this->output);
$this->assertContains('* Incomplete_Me rendered', $this->output);
}
public function testOneFileWithHtml()
{
$this->config['path'] = 'tests/data/claypit/tests/skipped/';
$this->config['class_name'] = 'SkipGuy';
$this->execute(array('suite' => 'skipped', '--single-file' => true, '--format' => 'html'));
$this->assertEquals(codecept_root_dir().'tests/data/scenarios/skipped.html', $this->filename);
$this->assertContains('<h3>I WANT TO MAKE IT INCOMPLETE</h3>', $this->content);
$this->assertContains('<h3>I WANT TO SKIP IT</h3>', $this->content);
$this->assertContains('<body><h3>', $this->content);
$this->assertContains('</body></html>', $this->content);
$this->assertContains('* Skip_Me rendered', $this->output);
$this->assertContains('* Incomplete_Me rendered', $this->output);
}
public function testDifferentPath()
{
$this->execute(array('suite' => 'dummy', '--single-file' => true, '--path' => 'docs'));
$this->assertEquals('docs/dummy.txt', $this->filename);
$this->assertContains('I WANT TO CHECK CONFIG EXISTS', $this->content);
$this->assertContains('* File_Exists rendered', $this->output);
}
}

View File

@@ -0,0 +1,52 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateStepObjectTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GenerateStepObject');
$this->config = array(
'actor' => 'HobbitGuy',
'path' => 'tests/shire',
);
}
public function testBasic()
{
$this->execute(array('suite' => 'shire', 'step' => 'Login', '--silent' => true));
$generated = $this->log[0];
$this->assertEquals(\Codeception\Configuration::supportDir().'Step/Shire/Login.php', $generated['filename']);
$this->assertContains('class Login extends \HobbitGuy', $generated['content']);
$this->assertContains('namespace Step\\Shire;', $generated['content']);
$this->assertIsValidPhp($generated['content']);
$this->assertIsValidPhp($this->content);
}
public function testNamespace()
{
$this->config['namespace'] = 'MiddleEarth';
$this->execute(array('suite' => 'shire', 'step' => 'Login', '--silent' => true));
$generated = $this->log[0];
$this->assertEquals(\Codeception\Configuration::supportDir().'Step/Shire/Login.php', $generated['filename']);
$this->assertContains('namespace MiddleEarth\Step\Shire;', $generated['content']);
$this->assertContains('class Login extends \MiddleEarth\HobbitGuy', $generated['content']);
$this->assertIsValidPhp($generated['content']);
$this->assertIsValidPhp($this->content);
}
public function testCreateInSubpath()
{
$this->execute(array('suite' => 'shire', 'step' => 'User/Login', '--silent' => true));
$generated = $this->log[0];
$this->assertEquals(
\Codeception\Configuration::supportDir().'Step/Shire/User/Login.php',
$generated['filename']
);
$this->assertIsValidPhp($this->content);
}
}

View File

@@ -0,0 +1,49 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateSuiteTest extends BaseCommandRunner
{
public $config = ['actor_suffix' => 'Guy'];
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GenerateSuite');
}
public function testBasic()
{
$this->execute(array('suite' => 'shire', 'actor' => 'Hobbit'), false);
$configFile = $this->log[1];
$this->assertEquals(\Codeception\Configuration::projectDir().'tests/shire.suite.yml', $configFile['filename']);
$conf = \Symfony\Component\Yaml\Yaml::parse($configFile['content']);
$this->assertEquals('Hobbit', $conf['actor']);
$this->assertContains('\Helper\Shire', $conf['modules']['enabled']);
$this->assertContains('Suite shire generated', $this->output);
$actor = $this->log[2];
$this->assertEquals(\Codeception\Configuration::supportDir().'Hobbit.php', $actor['filename']);
$this->assertContains('class Hobbit extends \Codeception\Actor', $actor['content']);
$helper = $this->log[0];
$this->assertEquals(\Codeception\Configuration::supportDir().'Helper/Shire.php', $helper['filename']);
$this->assertContains('namespace Helper;', $helper['content']);
$this->assertContains('class Shire extends \Codeception\Module', $helper['content']);
}
public function testGuyWithSuffix()
{
$this->execute(array('suite' => 'shire', 'actor' => 'HobbitTester'), false);
$configFile = $this->log[1];
$conf = \Symfony\Component\Yaml\Yaml::parse($configFile['content']);
$this->assertEquals('HobbitTester', $conf['actor']);
$this->assertContains('\Helper\Shire', $conf['modules']['enabled']);
$helper = $this->log[0];
$this->assertEquals(\Codeception\Configuration::supportDir().'Helper/Shire.php', $helper['filename']);
$this->assertContains('class Shire extends \Codeception\Module', $helper['content']);
}
}

View File

@@ -0,0 +1,57 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class GenerateTestTest extends BaseCommandRunner
{
protected function setUp()
{
$this->makeCommand('\Codeception\Command\GenerateTest');
$this->config = array(
'actor' => 'HobbitGuy',
'path' => 'tests/shire',
);
}
public function testBasic()
{
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
$this->assertEquals('tests/shire/HallUnderTheHillTest.php', $this->filename);
$this->assertContains('class HallUnderTheHillTest extends \Codeception\Test\Unit', $this->content);
$this->assertContains('Test was created in tests/shire/HallUnderTheHillTest.php', $this->output);
$this->assertContains('protected function _before()', $this->content);
$this->assertContains('protected function _after()', $this->content);
}
public function testCreateWithSuffix()
{
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillTest'));
$this->assertEquals('tests/shire/HallUnderTheHillTest.php', $this->filename);
$this->assertContains('Test was created in tests/shire/HallUnderTheHillTest.php', $this->output);
}
public function testCreateWithNamespace()
{
$this->execute(array('suite' => 'shire', 'class' => 'MiddleEarth\HallUnderTheHillTest'));
$this->assertEquals('tests/shire/MiddleEarth/HallUnderTheHillTest.php', $this->filename);
$this->assertContains('namespace MiddleEarth;', $this->content);
$this->assertContains('class HallUnderTheHillTest extends \Codeception\Test\Unit', $this->content);
$this->assertContains('Test was created in tests/shire/MiddleEarth/HallUnderTheHillTest.php', $this->output);
}
public function testCreateWithExtension()
{
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHillTest.php'));
$this->assertEquals('tests/shire/HallUnderTheHillTest.php', $this->filename);
$this->assertContains('class HallUnderTheHillTest extends \Codeception\Test\Unit', $this->content);
$this->assertContains('protected $tester;', $this->content);
$this->assertContains('@var \HobbitGuy', $this->content);
$this->assertContains('Test was created in tests/shire/HallUnderTheHillTest.php', $this->output);
}
public function testValidPHP()
{
$this->execute(array('suite' => 'shire', 'class' => 'HallUnderTheHill'));
$this->assertIsValidPhp($this->content);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Project\Command;
class MyCustomCommandTest extends \PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass()
{
require_once \Codeception\Configuration::dataDir() . 'register_command/examples/MyCustomCommand.php';
}
public function testHasCodeceptionCustomCommandInterface()
{
$command = new MyCustomCommand('commandName');
$this->assertInstanceOf('Codeception\CustomCommandInterface', $command);
}
public function testHasCommandName()
{
$commandName = MyCustomCommand::getCommandName();
$this->assertEquals('myProject:myCommand', $commandName);
}
}

View File

@@ -0,0 +1,46 @@
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
class SelfUpdateTest extends BaseCommandRunner
{
const COMMAND_CLASS = '\Codeception\Command\SelfUpdate';
public function testHasUpdate()
{
$this->setUpCommand('2.1.2', ['2.1.0-beta', '2.1.2', '2.1.3', '2.2.0-RC2']);
$this->execute();
$this->assertContains('Codeception version 2.1.2', $this->output);
$this->assertContains('A newer version is available: 2.1.3', $this->output);
}
public function testAlreadyLatest()
{
$this->setUpCommand('2.1.8', ['2.1.0-beta', '2.1.7', '2.1.8', '2.2.0-RC2']);
$this->execute();
$this->assertContains('Codeception version 2.1.8', $this->output);
$this->assertContains('You are already using the latest version.', $this->output);
}
/**
* @param string $version
* @param array $tags
*/
protected function setUpCommand($version, $tags)
{
$this->makeCommand(
self::COMMAND_CLASS,
false,
[
'getCurrentVersion' => function () use ($version) {
return $version;
},
'getGithubTags' => function () use ($tags) {
return $tags;
}
]
);
$this->config = [];
}
}