Checks that two variables are equal.
public assertEquals ( $expected, $actual, string $message = null ) : mixed | ||
$expected | ||
$actual | ||
$message | string | |
Результат | mixed |
public function testSetUnit() { $metric = new Metric(); $this->tester->assertFalse($metric->setUnit('Invalid'), 'Metric::setUnit invalid unit set failed!'); $metric->setUnit('Kilobits/Second'); $this->tester->assertEquals('Kilobits/Second', $metric->getUnit(), 'Metric::setUnit failed!'); }
/** * @dataProvider casesSeverityComparer * * @param int $expected * @param string $a * @param string $b */ public function testSeverityComparer($expected, $a, $b) { $fw = new FileWrapper([]); $class = new ReflectionClass(FileWrapper::class); $severityComparer = $class->getMethod('severityComparer'); $severityComparer->setAccessible(true); $this->tester->assertEquals($expected, $severityComparer->invoke($fw, $a, $b)); }
public function testGetYear() { /** * @var $object MTSXML */ $object = simplexml_load_file(Yii::getAlias('@data') . '/mts_report.xml', MTSXML::className()); $this->tester->assertEquals($object->getYear(), '2014'); }
/** * @param int $expected * @param array $a * @param array $b * * @dataProvider casesFailureComparer */ public function testFailureComparer($expected, array $a, array $b) { $rw = new ReportWrapper([]); $class = new ReflectionClass(ReportWrapper::class); $failureComparer = $class->getMethod('failureComparer'); $failureComparer->setAccessible(true); $this->tester->assertEquals($expected, $failureComparer->invoke($rw, $a, $b)); }
public function testValidateAttribute() { $this->tester->haveInCollection(Number::collectionName(), ['number' => '9101234567']); $this->specify("Test validate", function ($number, $expected) { $this->model['number'] = $number; $this->model->validate(['number']); $this->tester->assertEquals($expected, $this->model->hasErrors()); }, ['examples' => [['9101234567', false], ['1111111111', true], ['9121111111', true]]]); }
/** * Test resetiranja joba * @depends testRunJob * @param \UnitTester $I */ public function testResetJob(\UnitTester $I) { $job = $this->job; $this->jm->resetJob($job); $I->assertEquals(0, $job->getStatus()); $I->assertEquals(0, count($job->getReports())); $I->assertEquals(0, strlen($job->getLog())); $I->assertEmpty($job->getAlert()); }
public function tryToCreateNewChunk(UnitTester $I) { $data = ['id' => 1, 'name' => 'HEADER', 'description' => 'header stripe for main_site pages', 'snippet' => '<header>Header stripe</header>']; $r = new \Modvert\Resource\Modx\Chunk($data); $I->assertEquals(1, $r->getId()); $I->assertEquals(\Modvert\Resource\ResourceType::CHUNK, $r->getType()); $I->assertEquals('HEADER', $r->getName()); $I->assertEquals($data, $r->getCleanFields()); }
public function parseSubscriptionCancelled(UnitTester $I) { $parser = new \BB\Services\Payment\GoCardlessWebhookParser(); $parser->parseResponse($this->subscriptionCancelledPayload()); $I->assertEquals('cancelled', $parser->getAction()); $I->assertEquals('subscription', $parser->getResourceType()); $I->assertEquals(1, count($parser->getSubscriptions())); $I->assertEquals(0, count($parser->getBills())); $this->assertSubscriptionFormat($I, $parser->getSubscriptions()); }
public function testRun() { $result = 'Hello world'; $route = new router\Container(['test/route/{name:\\d}' => function ($request) use($result) { $this->tester->assertNotEmpty($request); $this->tester->assertTrue($request instanceof router\Request); return $result; }]); $out = $route->route('test/route/1'); $this->tester->assertEquals($out, $result); }
public function paymentDateChange(UnitTester $I) { $user = \BB\Entities\User::create(['given_name' => 'Jon', 'family_name' => 'Doe', 'email' => '*****@*****.**']); $I->assertEquals(0, $user->payment_day); $user->payment_day = 10; $user->save(); $I->assertEquals(10, $user->payment_day); $user->payment_day = 28; $user->save(); $I->assertEquals(28, $user->payment_day); $user->payment_day = 31; $user->save(); $I->assertEquals(1, $user->payment_day); }
/** * @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'); } }
/** * This way cannot be tested those cases when the lint process failed. * * @param int $exitCode * @param array $options * @param bool $withJar * @param bool $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' => 'my-working-dir', 'assetJarMapping' => ['report' => ['scssLintRun', 'report']], 'format' => 'JSON', 'failOn' => 'warning', 'failOnNoFiles' => false]; /** @var \Cheppers\Robo\ScssLint\Task\Run $task */ $task = Stub::construct(Task::class, [$options, []], ['processClass' => \Helper\Dummy\Process::class]); $processIndex = count(\Helper\Dummy\Process::$instances); \Helper\Dummy\Process::$prophecy[$processIndex] = ['exitCode' => $exitCode, 'stdOutput' => $expectedStdOutput]; $task->setLogger($container->get('logger')); $task->setOutput($mainStdOutput); $assetJar = null; if ($withJar) { $assetJar = new \Cheppers\AssetJar\AssetJar(); $task->setAssetJar($assetJar); } $result = $task->run(); $this->tester->assertEquals($exitCode, $result->getExitCode(), 'Exit code'); $this->tester->assertEquals($options['workingDirectory'], \Helper\Dummy\Process::$instances[$processIndex]->getWorkingDirectory(), 'Working directory'); if ($withJar) { /** @var \Cheppers\Robo\ScssLint\LintReportWrapper\ReportWrapper $reportWrapper */ $reportWrapper = $assetJar->getValue(['scssLintRun', 'report']); $this->tester->assertEquals(json_decode($expectedStdOutput, true), $reportWrapper->getReport(), 'Output equals with jar'); } else { $this->tester->assertContains($expectedStdOutput, $mainStdOutput->output, 'Output contains'); } }
public function testSetLanguageUrl() { $app = \Yii::$app; /** @var \bl\locale\UrlManager $urlManager */ $urlManager = clone $app->urlManager; \Codeception\Util\Debug::debug("Before parse request app language: {$app->language}"); $urlManager->detectInCookie = false; $urlManager->detectInSession = false; $language = 'uk-UA'; $url = "{$language}/site/index"; $request = $app->request; $request->setPathInfo($url); $parse = $urlManager->parseRequest($request); \Codeception\Util\Debug::debug("After parse request app language: {$app->language}"); $this->tester->assertEquals($language, \Yii::$app->language); }
public function testHideDefaoultLanguage() { $mockApp = $this->app; /** @var \bl\locale\UrlManager $urlManager */ $urlManager = clone $mockApp->urlManager; $urlManager->showDefault = false; $url = 'site/index'; \Codeception\Util\Debug::debug("Default language: {$mockApp->sourceLanguage}"); $actual = $urlManager->createUrl([$url, $urlManager->languageKey => 'en-US']); $expected = implode('/', ['', $url]); \Codeception\Util\Debug::debug("Hiden default language: {$actual}"); $this->tester->assertEquals($expected, $actual); $language = 'ru-RU'; $actual = $urlManager->createUrl([$url, $urlManager->languageKey => $language]); $expected = implode('/', ['', $language, $url]); \Codeception\Util\Debug::debug("Change language: {$actual}"); $this->tester->assertEquals($actual, $expected); }
/** * @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()); }
/** * @dataProvider casesReports */ public function testAll(array $expected, array $report) { $rw = new ReportWrapper($report); $this->tester->assertEquals($expected['countFiles'], $rw->countFiles()); $this->tester->assertEquals($expected['numOfErrors'], $rw->numOfErrors()); $this->tester->assertEquals($expected['numOfWarnings'], $rw->numOfWarnings()); $this->tester->assertEquals($expected['highestSeverity'], $rw->highestSeverity()); /** * @var string $filePath * @var \Cheppers\Robo\Phpcs\LintReportWrapper\FileWrapper $fw */ foreach ($rw->yieldFiles() as $filePath => $fw) { $file = array_shift($report['files']); $this->tester->assertEquals($file['filePath'], $fw->filePath()); $this->tester->assertEquals($file['errors'], $fw->numOfErrors()); $this->tester->assertEquals($file['warnings'], $fw->numOfWarnings()); $this->tester->assertEquals($file['__highestSeverity'], $fw->highestSeverity()); $this->tester->assertEquals($file['__stats'], $fw->stats()); /** * @var int $i * @var \Cheppers\LintReport\FailureWrapperInterface $failureWrapper */ foreach ($fw->yieldFailures() as $i => $failureWrapper) { $message = $file['messages'][$i]; $this->tester->assertEquals($message['type'], $failureWrapper->severity()); $this->tester->assertEquals($message['source'], $failureWrapper->source()); $this->tester->assertEquals($message['line'], $failureWrapper->line()); $this->tester->assertEquals($message['column'], $failureWrapper->column()); $this->tester->assertEquals($message['message'], $failureWrapper->message()); } } }
<?php $I = new UnitTester($scenario); $I->wantTo('mark as done deposit ticket'); $app = \Slim\Slim::getInstance(); $app->container->singleton("DepositMarkAsDoneService", function () use($app) { $deposit_repository = \Codeception\Util\Stub::make("\\Mabes\\Entity\\DepositRepository", ["findOneBy" => function () { $deposit = new \Mabes\Entity\Deposit(); $deposit->setStatus(\Mabes\Entity\Deposit::STATUS_OPEN); return $deposit; }, "save" => function () { return true; }]); $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () { return true; }]); $validator = $app->container->get("Validator"); return new \Mabes\Service\DepositMarkAsDoneService($deposit_repository, $validator, $event_emitter); }); $data = ["deposit_id" => 1]; $command = new \Mabes\Service\Command\DepositMarkAsDoneCommand(); $command->massAssignment($data); $service = $app->container->get("DepositMarkAsDoneService"); $I->assertEquals(true, $service->execute($command)); // EOF
<?php use Carbon\Carbon; $I = new UnitTester($scenario); $I->wantTo('confirm the grace period dates are correct'); $paypalDate = \BB\Helpers\MembershipPayments::getSubGracePeriodDate('paypal'); //Make sure its a date that's returned $I->assertEquals(get_parent_class($paypalDate), 'DateTime'); //Confirm the date is what we expect $I->assertEquals(Carbon::now()->subDays(7)->setTime(0, 0, 0), $paypalDate);
public function tryToMatchValue(UnitTester $I) { $array = [0 => ["file" => "bin/modvert.web.php", "index" => " ", "work_tree" => "M"], 1 => ["file" => "src/Modvert/Application.php", "index" => " ", "work_tree" => "M"], 2 => ["file" => "tests/unit/ApplicationCest.php", "index" => " ", "work_tree" => "M"], 3 => ["file" => "src/Modvert/Helper/Git.php", "index" => " ", "work_tree" => "M"]]; $expected = ['src/Modvert/Application.php', 'src/Modvert/Helper/Git.php']; $I->assertEquals($expected, ArrayHelper::matchValue($array, 'file', '/^src/')); }
public function testDeleteMethod() { $arrayer = new \Mascame\Arrayer\Arrayer(['test' => 'first value']); $arrayer->delete('test'); $this->tester->assertEquals(null, $arrayer->get('test')); }
Location::create(['name' => 'Cardiff', 'lat' => 51.4833, 'lng' => 3.1833]); Location::create(['name' => 'Newport', 'lat' => 51.5833, 'lng' => 3.0]); Location::create(['name' => 'Swansea', 'lat' => 51.6167, 'lng' => 3.95]); Location::create(['name' => 'London', 'lat' => 51.5072, 'lng' => 0.1275]); /*for ($i = 0; $i < 1000; $i++) { Location::create(['location' => $i, 'lat' => $i, 'lng' => $i, 'updated_at' => $i, 'created_at' => $i]); }*/ $I = new UnitTester($scenario); $lat = 51.4833; $lng = 3.1833; $location = new Location(); $locations = $location->lat($lat)->lng($lng)->within(20, 'miles')->get(); $I->wantTo('find locations within 5 miles'); $locations = Location::within(5, 'miles', $lat, $lng)->get(); $I->assertEquals(1, $locations->count(), 'One location found within 5 miles'); $I->wantTo('find 2 locations within 132000 feet (25 miles)'); $locations = Location::within(132000, 'feet', $lat, $lng)->get(); $I->assertEquals(2, $locations->count(), 'One location found within 132000 feet'); $I->wantTo('find locations within 55 miles'); $locations = Location::within(55, 'miles', $lat, $lng)->get(); $I->assertEquals(3, $locations->count(), 'Three locations found within 55 miles'); $I->wantTo('find locations within 5 kilometers'); $locations = Location::within(5, 'kilometers', $lat, $lng)->get(); $I->assertEquals(1, $locations->count(), 'One location found within 5 kilometers'); $I->wantTo('find locations within 5 nautical miles'); $locations = Location::within(5, 'nautical_miles', $lat, $lng)->get(); $I->assertEquals(1, $locations->count(), 'One location found within 5 nautical miles'); $I->wantTo('find locations within 5000 meters'); $locations = Location::within(5000, 'meters', $lat, $lng)->get(); $I->assertEquals(1, $locations->count(), 'One location found within 5000 meters');
public function testCategories() { // 1. Add category taxonomy $taxonomy = new TaxonomyDef(); $taxonomy->name = 'test_categories'; $taxonomy->class = CategoryTerm::className(); $taxonomy->data_table = 'sample_categories'; $taxonomy->ref_table = SampleTable::className(); // 2. Create data table $categoryTerm = Yii::createObject($taxonomy->attributes); $migration = $categoryTerm->install(); $this->runMigration($migration); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name); $this->tester->assertTrue($categoryTerm->isInstalled(), 'The taxonomy must be installed.'); // ***************CategoryTerm::createCategory() tests start***************** // 3. Add a root category of type array $rootTermName = 'root'; $this->assertExceptionThrown(function () use($categoryTerm, $rootTermName) { $categoryTerm->createCategory([$rootTermName]); }); // 3a. Create a root term $rootTerm = $categoryTerm->createCategory($rootTermName); $this->tester->assertNotNull($rootTerm); $this->tester->assertEquals($rootTermName, $rootTerm->term); // 4. Add a child of wrong type $this->assertExceptionThrown(function () use($categoryTerm, $rootTerm) { $categoryTerm->createCategory((int) $rootTerm->id, 321); }); // 5. Adding an array of children where the child name is not a string $this->assertExceptionThrown(function () use($categoryTerm, $rootTerm) { $categoryTerm->createCategory((int) $rootTerm->id, [321]); }); // 6. Attatching children to a non-existing parent $this->assertExceptionThrown(function () use($categoryTerm) { $categoryTerm->createCategory(500, ['Test', 'Test2']); }); // 7. Adding a child to a parent $childName1 = 'child1'; $result = $categoryTerm->createCategory((int) $rootTerm->id, [$childName1]); $this->tester->assertEquals(1, count($result)); $this->tester->assertEquals($childName1, $result[0]->term); $this->tester->assertTrue($categoryTerm->hasParent($result[0]->id)); $this->tester->assertTrue($categoryTerm->hasChildren($rootTerm->id)); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name); $terms = $categoryTerm->getTerms(); $this->tester->assertEquals(2, count($terms)); $this->tester->assertContains($rootTermName, $terms); $this->tester->assertContains($childName1, $terms); $childTerm1 = $result[0]; // ***************CategoryTerm::createCategory() tests end***************** // ***************CategoryTerm::addTerm() tests start***************** // 1. Assigning one existing term to an object $terms = $categoryTerm->addTerm(1, $rootTerm->id); $this->tester->assertEquals(1, count($terms)); $this->tester->assertEquals($rootTermName, $terms[0]->term); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $rootTerm = $categoryTerm->getTaxonomyTerm($rootTermName); $terms = $categoryTerm->getTerms(1); $this->tester->assertEquals(1, $categoryTerm->total_count); $this->tester->assertEquals(1, $rootTerm->total_count); $this->tester->assertEquals(1, count($terms)); $this->tester->assertContains($rootTermName, $terms); // 2. Assigning one existing term to an object as an array $terms = $categoryTerm->addTerm(1, [$childTerm1->id]); $this->tester->assertEquals(1, count($terms)); $this->tester->assertEquals($childName1, $terms[0]->term); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $childTerm = $categoryTerm->getTaxonomyTerm($childName1); $terms = $categoryTerm->getTerms(1); $this->tester->assertEquals(2, $categoryTerm->total_count); $this->tester->assertEquals(1, $childTerm->total_count); $this->tester->assertEquals(2, count($terms)); $this->tester->assertContains($rootTermName, $terms); $this->tester->assertContains($childName1, $terms); // ***************CategoryTerm::addTerm() tests end***************** // ***************CategoryTerm::setTerms() tests start***************** $childName2 = 'child2'; $childName3 = 'child3'; $childName4 = 'child4'; $createdTerms = $categoryTerm->createCategory((int) $rootTerm->id, [$childName2, $childName3, $childName4]); $terms = $categoryTerm->getTerms(1); $this->tester->assertEquals(2, count($terms)); // 1. Change the terms where the object is assigned $result = $categoryTerm->setTerms(1, [$rootTerm->id => [$createdTerms[0]->id, $createdTerms[1]->id]]); $terms = $categoryTerm->getTerms(1); $this->tester->assertEquals(2, count($result)); $this->tester->assertEquals(3, count($terms)); $this->tester->assertContains($childName2, $terms); $this->tester->assertContains($childName3, $terms); // ***************CategoryTerm::setTerms() tests end***************** // ***************getChildren(), hasChildren(), getParent(), hasParent() tests start***************** $this->tester->assertTrue($categoryTerm->hasChildren($rootTerm->id)); $children = $categoryTerm->getChildren($rootTerm->id); $this->tester->assertEquals(4, count($children)); $this->tester->assertTrue($categoryTerm->hasParent($childTerm->id)); $parent = $categoryTerm->getParent($childTerm->id); $this->tester->assertNotNull($parent); $this->tester->assertEquals($rootTermName, $parent->term); // ***************getChildren(), hasChildren(), getParent(), hasParent() tests end***************** }
/** * getUid */ public function testGetUidTestUser() { $this->getTestUsers(); $this->tester->assertEquals($this->test_user->id, $this->facebook->getUid($this->test_user->access_token)); }
public function testGetAndSetAction() { $this->request->setAction('non-stop-action'); $this->tester->assertEquals($this->request->getAction(), 'non-stop-action'); }
public function testCategories() { // 1. Add category taxonomy $taxonomy = new TaxonomyDef(); $taxonomy->name = 'test_categories'; $taxonomy->class = CategoryTerm::className(); $taxonomy->data_table = 'sample_categories'; $taxonomy->ref_table = SampleTable::className(); // 2. Create data table $categoryTerm = Yii::createObject($taxonomy->attributes); $migration = $categoryTerm->install(); $this->runMigration($migration); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name); $this->tester->assertTrue($categoryTerm->isInstalled(), 'The taxonomy must be installed.'); // 3. Add a root category without an object id $rootTermName = 'root'; $categoryTerm->addTerm(null, [$rootTermName]); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $rootTerm = $categoryTerm->getTaxonomyTerm($rootTermName); $terms = $categoryTerm->getTerms(null); // Check whether everything is properly inserted $this->tester->assertEquals(0, $categoryTerm->total_count); $this->tester->assertEquals(0, $rootTerm->total_count); $this->tester->assertEquals(1, count($terms)); $this->tester->assertEquals($rootTermName, $terms[0]); // Check for parents $this->tester->assertNull($categoryTerm->getParent($terms[0])); $this->tester->assertFalse($categoryTerm->hasParent($terms[0])); // Check for children $this->tester->assertEmpty($categoryTerm->getChildren($terms[0])); $this->tester->assertFalse($categoryTerm->hasChildren($terms[0])); // 4. Add child to the root $childTermName1 = 'child1'; $categoryTerm->addTerm(null, [$rootTermName => $childTermName1]); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $childTerm1 = $categoryTerm->getTaxonomyTerm($childTermName1); $terms = $categoryTerm->getTerms(null); // Check whether everything is properly inserted $this->tester->assertEquals(0, $categoryTerm->total_count); $this->tester->assertEquals(0, $childTerm1->total_count); $this->tester->assertEquals(2, count($terms)); $this->tester->assertContains($childTermName1, $terms); // Check for parents $this->tester->assertTrue($categoryTerm->hasParent($childTermName1)); $this->tester->assertEquals($rootTermName, $categoryTerm->getParent($childTermName1)); // Check for children $this->tester->assertEmpty($categoryTerm->getChildren($childTermName1)); $this->tester->assertFalse($categoryTerm->hasChildren($childTermName1)); // Check the children of the root $rootChildren = $categoryTerm->getChildren($rootTermName); $this->tester->assertTrue($categoryTerm->hasChildren($rootTermName)); $this->tester->assertEquals(1, count($rootChildren)); $this->tester->assertContains($childTermName1, $rootChildren); // 5. Test adding more than one child at a time $childTermName2 = 'child2'; $childTermName3 = 'child3'; $categoryTerm->addTerm(null, [$rootTermName => [$childTermName2, $childTermName3]]); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $terms = $categoryTerm->getTerms(null); // Test whether all child terms are attached to the root $this->tester->assertEquals(4, count($terms)); $this->tester->assertEquals(3, count($categoryTerm->getChildren($rootTermName))); // 6. Test adding term to an existing object $rootTermName2 = 'root2'; $categoryTerm->addTerm(1, $rootTermName2); // Add a term as a string, not as an array $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $rootTerm2 = $categoryTerm->getTaxonomyTerm($rootTermName2); // Check whether everything is properly inserted $terms = $categoryTerm->getTerms(1); $this->tester->assertEquals(1, count($terms)); $this->tester->assertContains($rootTermName2, $terms); // Check the counters $this->tester->assertEquals(1, $categoryTerm->total_count); $this->tester->assertEquals(1, $rootTerm2->total_count); // Check whether all terms will be returned $terms = $categoryTerm->getTerms(null); $this->tester->assertEquals(5, count($terms)); // Add child $childTermName4 = 'child4'; $categoryTerm->addTerm(1, [$rootTermName2 => $childTermName4]); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $rootTerm2 = $categoryTerm->getTaxonomyTerm($rootTermName2); $childTerm4 = $categoryTerm->getTaxonomyTerm($childTermName4); $terms = $categoryTerm->getTerms(1); $this->tester->assertEquals(2, count($terms)); $this->tester->assertEquals(2, $categoryTerm->total_count); $this->tester->assertEquals(1, $rootTerm2->total_count); $this->tester->assertEquals(1, $childTerm4->total_count); // 7. Loop detection test. Add the root as a child of one of the children $exceptionTrown = false; try { $categoryTerm->addTerm(null, [$childTermName3 => $rootTermName]); } catch (Exception $ex) { $exceptionTrown = true; } $this->tester->assertTrue($exceptionTrown); // 8. Adding two hierarchies at once TaxonomyTerms::deleteAll(); $categoryTerm->addTerm(null, [$rootTermName => [$childTermName1, $childTermName2], $rootTermName2]); $categoryTerm = $this->getTaxonomy()->getTerm($taxonomy->name, true); $terms = $categoryTerm->getTerms(null); $this->tester->assertEquals(4, count($terms)); }
/** * @param array $expected * @param array $args * * @dataProvider casesMergeReports */ public function testMergeReports(array $expected, array $args) { $callable = Utils::class . '::mergeReports'; $this->tester->assertEquals($expected, call_user_func_array($callable, $args)); }
<?php use BB\Entities\Payment; use BB\Entities\User; $I = new UnitTester($scenario); $I->wantTo('confirm the payment helper fetches the correct payment date'); //Create a user record $user = User::create(['given_name' => 'Test', 'family_name' => 'Person', 'email' => '*****@*****.**']); $date = \BB\Helpers\MembershipPayments::lastUserPaymentDate($user->id); $I->assertFalse($date, 'Date should be false as no payments exist'); //Create some payment records \BB\Entities\SubscriptionCharge::create(['user_id' => $user->id, 'charge_date' => '2014-01-01', 'payment_date' => '2014-01-01', 'status' => 'paid']); Payment::create(['reason' => 'subscription', 'source' => 'other', 'user_id' => $user->id, 'amount' => 20, 'amount_minus_fee' => 20, 'status' => 'paid', 'created_at' => '2014-01-01']); \BB\Entities\SubscriptionCharge::create(['user_id' => $user->id, 'charge_date' => '2014-06-01', 'status' => 'processing']); Payment::create(['reason' => 'subscription', 'source' => 'other', 'user_id' => $user->id, 'amount' => 20, 'amount_minus_fee' => 20, 'status' => 'pending', 'created_at' => '2014-06-01']); \BB\Entities\SubscriptionCharge::create(['user_id' => $user->id, 'charge_date' => '2014-08-01', 'status' => 'cancelled']); Payment::create(['reason' => 'subscription', 'source' => 'other', 'user_id' => $user->id, 'amount' => 20, 'amount_minus_fee' => 20, 'status' => 'cancelled', 'created_at' => '2014-08-01']); //Now we have some payments re-fetch the last payment date $date = \BB\Helpers\MembershipPayments::lastUserPaymentDate($user->id); //Make sure its a date that's returned $I->assertEquals(get_parent_class($date), 'DateTime'); //Confirm the datetime matched the first payment record, the only paid one $I->assertEquals(new \Carbon\Carbon('2014-01-01'), $date);
<?php $I = new UnitTester($scenario); $I->wantTo('confirm the stats helper works as expected'); $I->assertEquals(0, \BB\Helpers\StatsHelper::roundToNearest(2), '2 should round to 0'); $I->assertEquals(5, \BB\Helpers\StatsHelper::roundToNearest(4), '4 should round to 5'); $I->assertEquals(5, \BB\Helpers\StatsHelper::roundToNearest(5), '5 should stay as 5'); $I->assertEquals(5, \BB\Helpers\StatsHelper::roundToNearest(6), '6 should round down to 5'); $I->assertEquals(10, \BB\Helpers\StatsHelper::roundToNearest(7.5), '7.5 should round up to 10'); $I->assertEquals(10, \BB\Helpers\StatsHelper::roundToNearest(10), '10 should stay as 10');