Skip to content

Commit eda56a5

Browse files
committed
Add further tests for script decisions
1 parent 77b3cf0 commit eda56a5

File tree

5 files changed

+221
-18
lines changed

5 files changed

+221
-18
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Tooly\Tests\Script\Decision;
4+
5+
use Tooly\Script\Configuration;
6+
use Tooly\Script\Helper;
7+
8+
/**
9+
* @package Tooly\Tests\Script\Decision
10+
*/
11+
abstract class DecisionTestCase extends \PHPUnit_Framework_TestCase
12+
{
13+
protected $helper;
14+
15+
protected $configuration;
16+
17+
public function setUp()
18+
{
19+
$this->helper = $this
20+
->getMockBuilder(Helper::class)
21+
->disableOriginalConstructor()
22+
->getMock();
23+
24+
$this->configuration = $this
25+
->getMockBuilder(Configuration::class)
26+
->disableOriginalConstructor()
27+
->getMock();
28+
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Tooly\Tests\Script\Decision;
4+
5+
use Tooly\Factory\ToolFactory;
6+
use Tooly\Model\Tool;
7+
use Tooly\Script\Decision\FileAlreadyExistDecision;
8+
9+
/**
10+
* @package Tooly\Tests\Script\Decision
11+
*/
12+
class FileAlreadyExistDecisionTest extends DecisionTestCase
13+
{
14+
public function testIfFileNotAlreadyExistReturnsTrue()
15+
{
16+
$this->helper
17+
->expects($this->once())
18+
->method('isFileAlreadyExist')
19+
->willReturn(false);
20+
21+
$tool = $this
22+
->getMockBuilder(Tool::class)
23+
->disableOriginalConstructor()
24+
->getMock();
25+
26+
$decision = new FileAlreadyExistDecision($this->configuration, $this->helper);
27+
$this->assertTrue($decision->canProceed($tool));
28+
}
29+
30+
public function testIfFileAlreadyExistReturnsFalse()
31+
{
32+
$this->helper
33+
->expects($this->once())
34+
->method('isFileAlreadyExist')
35+
->willReturn(true);
36+
37+
$tool = $this
38+
->getMockBuilder(Tool::class)
39+
->disableOriginalConstructor()
40+
->getMock();
41+
42+
$decision = new FileAlreadyExistDecision($this->configuration, $this->helper);
43+
$this->assertFalse($decision->canProceed($tool));
44+
}
45+
46+
public function testCanGetReason()
47+
{
48+
$decision = new FileAlreadyExistDecision($this->configuration, $this->helper);
49+
$this->assertRegExp('/info/', $decision->getReason());
50+
}
51+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Tooly\Tests\Script\Decision;
4+
5+
use Tooly\Factory\ToolFactory;
6+
use Tooly\Model\Tool;
7+
use Tooly\Script\Decision\IsAccessibleDecision;
8+
9+
/**
10+
* @package Tooly\Tests\Script\Decision
11+
*/
12+
class IsAccessibleDecisionTest extends DecisionTestCase
13+
{
14+
public function testNotAccessibleToolUrlReturnsFalse()
15+
{
16+
$this->helper
17+
->expects($this->once())
18+
->method('isAccessible')
19+
->willReturn(false);
20+
21+
$decision = new IsAccessibleDecision($this->configuration, $this->helper);
22+
$this->assertFalse($decision->canProceed(ToolFactory::createTool('tool', __DIR__, [])));
23+
}
24+
25+
public function testEmptySignUrlReturnsTrue()
26+
{
27+
$this->helper
28+
->expects($this->once())
29+
->method('isAccessible')
30+
->willReturn(true);
31+
32+
$decision = new IsAccessibleDecision($this->configuration, $this->helper);
33+
$this->assertTrue($decision->canProceed(ToolFactory::createTool('tool', __DIR__, [])));
34+
}
35+
36+
public function testNotAccessibleToolSignUrlReturnsFalse()
37+
{
38+
$this->helper
39+
->method('isAccessible')
40+
->will($this->onConsecutiveCalls(true, false));
41+
42+
$decision = new IsAccessibleDecision($this->configuration, $this->helper);
43+
$this->assertFalse($decision->canProceed(ToolFactory::createTool('tool', __DIR__, [
44+
'sign-url' => 'sign-url'
45+
])));
46+
}
47+
48+
public function testAccessibleUrlsWillReturnTrue()
49+
{
50+
$this->helper
51+
->method('isAccessible')
52+
->will($this->onConsecutiveCalls(true, true));
53+
54+
$decision = new IsAccessibleDecision($this->configuration, $this->helper);
55+
$this->assertTrue($decision->canProceed(ToolFactory::createTool('tool', __DIR__, [
56+
'sign-url' => 'sign-url'
57+
])));
58+
}
59+
60+
public function testCanGetReason()
61+
{
62+
$decision = new IsAccessibleDecision($this->configuration, $this->helper);
63+
$this->assertRegExp('/error/', $decision->getReason());
64+
}
65+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Tooly\Tests\Script\Decision;
4+
5+
use Tooly\Factory\ToolFactory;
6+
use Tooly\Model\Tool;
7+
use Tooly\Script\Decision\IsVerifiedDecision;
8+
9+
/**
10+
* @package Tooly\Tests\Script\Decision
11+
*/
12+
class IsVerifiedDecisionTest extends DecisionTestCase
13+
{
14+
public function testEmptySignUrlReturnsTrue()
15+
{
16+
$tool = $this
17+
->getMockBuilder(Tool::class)
18+
->disableOriginalConstructor()
19+
->getMock();
20+
21+
$tool
22+
->expects($this->once())
23+
->method('getSignUrl')
24+
->willReturn(null);
25+
26+
$decision = new IsVerifiedDecision($this->configuration, $this->helper);
27+
$this->assertTrue($decision->canProceed($tool));
28+
}
29+
30+
public function testVerificationReturnsBool()
31+
{
32+
$helper = $this->helper;
33+
$helper
34+
->expects($this->at(0))
35+
->method('isVerified')
36+
->willReturn(true);
37+
38+
$helper
39+
->expects($this->at(1))
40+
->method('isVerified')
41+
->willReturn(false);
42+
43+
$tool = $this
44+
->getMockBuilder(Tool::class)
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$tool
49+
->expects($this->exactly(2))
50+
->method('getUrl')
51+
->willReturn('foo');
52+
53+
$tool
54+
->expects($this->exactly(4))
55+
->method('getSignUrl')
56+
->willReturn('bar');
57+
58+
$decision = new IsVerifiedDecision($this->configuration, $helper);
59+
60+
$this->assertTrue($decision->canProceed($tool));
61+
$this->assertFalse($decision->canProceed($tool));
62+
}
63+
64+
public function testCanGetReason()
65+
{
66+
$decision = new IsVerifiedDecision($this->configuration, $this->helper);
67+
$this->assertRegExp('/error/', $decision->getReason());
68+
}
69+
}

tests/Script/Decision/OnlyDevDecisionTest.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,8 @@
1010
/**
1111
* @package Tooly\Tests\Script\Decision
1212
*/
13-
class OnlyDevDecisionTest extends \PHPUnit_Framework_TestCase
13+
class OnlyDevDecisionTest extends DecisionTestCase
1414
{
15-
private $helper;
16-
17-
private $configuration;
18-
19-
public function setUp()
20-
{
21-
$this->helper = $this
22-
->getMockBuilder(Helper::class)
23-
->disableOriginalConstructor()
24-
->getMock();
25-
26-
$this->configuration = $this
27-
->getMockBuilder(Configuration::class)
28-
->disableOriginalConstructor()
29-
->getMock();
30-
}
31-
3215
public function testOnlyDevToolInNonDevModeReturnsFalse()
3316
{
3417
$helper = clone $this->helper;
@@ -99,4 +82,10 @@ public function testNonOnlyDevToolInDevModeReturnsTrue()
9982
$decision = new OnlyDevDecision($configuration, $helper);
10083
$this->assertTrue($decision->canProceed($tool));
10184
}
85+
86+
public function testCanGetReason()
87+
{
88+
$decision = new OnlyDevDecision($this->configuration, $this->helper);
89+
$this->assertRegExp('/comment/', $decision->getReason());
90+
}
10291
}

0 commit comments

Comments
 (0)