44
55use Behat \Behat \Context \Context ;
66use Behat \Behat \Context \SnippetAcceptingContext ;
7+ use Behat \Behat \Tester \Exception \PendingException ;
78use Behat \Gherkin \Node \PyStringNode ;
89use Behat \Gherkin \Node \TableNode ;
910
1213 */
1314class TaskContext implements Context, SnippetAcceptingContext
1415{
16+ const PHING_BIN_PATH = 'vendor/bin/phing ' ;
17+
18+ /**
19+ * @var string
20+ */
21+ protected $ token ;
22+
23+ /**
24+ * @var string
25+ */
26+ protected $ project ;
27+
28+ /**
29+ * @var string
30+ */
31+ protected $ reference ;
32+
33+ /**
34+ * @var string
35+ */
36+ protected $ lastOutput ;
37+
1538 /**
1639 * Initializes context.
1740 *
@@ -22,4 +45,61 @@ class TaskContext implements Context, SnippetAcceptingContext
2245 public function __construct ()
2346 {
2447 }
48+
49+ /**
50+ * @Given I've the token :token
51+ */
52+ public function setToken ($ token )
53+ {
54+ $ this ->token = $ token ;
55+ }
56+
57+ /**
58+ * @Given the project :project
59+ */
60+ public function setProject ($ project )
61+ {
62+ $ this ->project = $ project ;
63+ }
64+
65+ /**
66+ * @Given the reference :reference
67+ */
68+ public function setReference ($ reference )
69+ {
70+ $ this ->reference = $ reference ;
71+ }
72+
73+ /**
74+ * @When I use the continuousphp package task
75+ */
76+ public function runPackageTask ()
77+ {
78+ $ command = self ::PHING_BIN_PATH . ' config package '
79+ . " -Dtoken= " . $ this ->token
80+ . " -Dproject= " . $ this ->project
81+ . " -Dreference= " . $ this ->reference ;
82+
83+ exec ($ command , $ output , $ return );
84+
85+ if ($ return ) {
86+ throw new \RuntimeException (implode (PHP_EOL , $ output ), $ return );
87+ }
88+
89+ $ this ->lastOutput = implode (PHP_EOL , $ output );
90+ }
91+
92+ /**
93+ * @Then I should retrieve a valid download url
94+ */
95+ public function isValidDownloadUrl ()
96+ {
97+ $ regex = "/---PACKAGE_URL:(.*)---/ " ;
98+ \PHPUnit_Framework_Assert::assertRegExp ($ regex , $ this ->lastOutput );
99+
100+ preg_match ($ regex , $ this ->lastOutput , $ matches );
101+ $ url = $ matches [1 ];
102+
103+ \PHPUnit_Framework_Assert::assertNotEquals ('${package.url} ' , $ url );
104+ }
25105}
0 commit comments