Piotr Woszczyk @ 2017
<?php
class MakoTest extends \PHPUnit_Framework_TestCase
{
public function testDeadline()
{
$expected = 'yesterday';
$current = 'tomorrow';
$this->assertEquals($expected, $current);
}
}<?php
use Drupal\makolab\JiraChecker;
class MakoTest extends \PHPUnit_Framework_TestCase
{
public function testDeadline()
{
$jiraChecker = new JiraChecker();
$deadline = $jiraChecker->getCurrent()->getDeadline();
$deadlineTimestamp = $deadline->getTimestamp();
$current = new \DateTime();
$currentTimestamp = $current->getTimestamp();
$this->assertLessThan($deadlineTimestamp, $currentTimestamp);
}
}<?php
use Drupal\makolab\JiraChecker;
class MakoTest extends \PHPUnit_Framework_TestCase
{
public function testDeadline()
{
$jiraChecker = new JiraChecker();
$deadline = $jiraChecker->getCurrent()->getDeadline();
$deadlineTimestamp = $deadline->getTimestamp();
$current = new \DateTime();
$currentTimestamp = $current->getTimestamp();
$this->assertLessThan($deadlineTimestamp, $currentTimestamp);
return $deadline;
}
/**
* @depends testDeadline
*/
public function testDeadlineBufor($deadline)
{
$deadline->modify('+1 day');
$deadlineTimestamp = $deadline->getTimestamp();
$current = new \DateTime();
$currentTimestamp = $current->getTimestamp();
$this->assertLessThan($deadlineTimestamp, $currentTimestamp);
}
}<?php
use Drupal\makolab\JiraChecker;
class MakoTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider projectsProvider
*/
public function testDeadline($projectName, $closeDate)
{
$jiraChecker = new JiraChecker();
$deadline = $jiraChecker->getByName($projectName)->getDeadline();
$deadlineTimestamp = $deadline->getTimestamp();
$closeTimestamp = $closeDate->getTimestamp();
$this->assertLessThan($deadlineTimestamp, $closeTimestamp);
}
public function projectsProvider()
{
return [
['paradyz', \DateTime('2017-07-01')],
['ecc', \DateTime('2017-10-01')]
];
}
}<?php
use Drupal\makolab\JiraChecker;
class MakoTest extends \PHPUnit_Framework_TestCase
{
protected $jiraChecker;
protected function setUp()
{
parent::setUp();
$this->jiraChecker = new JiraChecker();
}
public function testDeadline()
{
$deadline = $this->jiraChecker->getCurrent()->getDeadline();
$deadlineTimestamp = $deadline->getTimestamp();
$current = new \DateTime();
$currentTimestamp = $current->getTimestamp();
$this->assertLessThan($deadlineTimestamp, $currentTimestamp);
}
}<?php
class MakoTest extends \PHPUnit_Framework_TestCase
{
protected $jiraChecker;
protected function setUp()
{
parent::setUp();
$mockBuilder = $this->getMockBuilder('\Drupal\makolab\Project');
$projectStub = $mockBuilder->getMock();
$projectStub->method('getDeadline')->willReturn(new \DateTime());
$mockBuilder = $this->getMockBuilder('\Drupal\makolab\JiraChecker');
$jiraStub = $mockBuilder->getMock();
$jiraStub->method('getCurrent')->willReturn($projectStub);
$this->jiraChecker = $jiraStub;
}
public function testDeadline()
{
$deadline = $this->jiraChecker->getCurrent()->getDeadline();
$deadlineTimestamp = $deadline->getTimestamp();
$current = new \DateTime();
$currentTimestamp = $current->getTimestamp();
$this->assertLessThan($deadlineTimestamp, $currentTimestamp);
}
}<?php
namespace Drupal\Tests\makolab\Unit\Helper;
use Drupal\Tests\UnitTestCase;
use Drupal\makolab\Helper\TextTool;
/**
* @author piotr.woszczyk
* @coversDefaultClass \Drupal\makolab\Helper\TextTool
* @group makolab
*/
class TextToolTest extends UnitTestCase
{
/**
* @var \Drupal\makolab\Helper\TextTool
*/
protected $textTool;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->textTool = new TextTool();
}
/**
* @covers \Drupal\makolab\Helper\TextTool::simplify
* @dataProvider stringsProvider
*/
public function testSimplify($actual, $expected)
{
$this->assertEquals($expected, $this->textTool->simplify($actual));
}
public function stringsProvider()
{
return [
['paRadyz', 'paradyz'],
[' paraDyż', 'paradyz'],
['paradyŻ ', 'paradyz'],
['par adyz', 'par adyz'],
[' par ądyz', 'par adyz'],
['par adyz ', 'par adyz'],
['PARADYZ', 'paradyz'],
];
}
}php web/core/scripts/run-tests.sh --module makolab
Drupal test run
---------------
Tests to be run:
- Drupal\Tests\makolab\Unit\Helper\TextToolTest
Test run started:
Friday, November 24, 2017 - 04:33
Test summary
------------
Drupal\Tests\makolab\Unit\Helper\TextToolTest 7 passes
Test run duration: 0 secprotected function setUp() {
parent::setUp();
$this->root = static::getDrupalRoot();
$this->initFileCache();
$this->bootEnvironment();
$this->bootKernel();
}<?php
class AwardsTest extends KernelTestBase
{
/**
* @var array
*/
public static $modules = ['makolab', 'user', 'simpletest'];
}<?php
namespace Drupal\Tests\makolab\Kernel\Custom;
use Drupal\KernelTests\KernelTestBase;
/**
* @author piotr.woszczyk
* @coversDefaultClass \Drupal\makolab\Custom\Awards
* @group makolab
*/
class AwardsTest extends KernelTestBase
{
/**
* @var array
*/
public static $modules = ['makolab', 'user', 'simpletest'];
/**
* @var \Drupal\makolab\Custom\Awards
*/
protected $awardsService;
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->awardsService = \Drupal::service('makolab.custom.awards');
}
/*
* @covers ::get
*/
public function testClass()
{
$this->assertInstanceOf(
'\Drupal\makolab\Custom\Awards',
$this->awardsService
);
}
}