Skip to content

Commit

Permalink
Added feature issue154
Browse files Browse the repository at this point in the history
I went with a testing approach that's little more high level (matching the Application __toString() output), and initiates the resources like in the "Tyrell" example.
  • Loading branch information
drkibitz committed Jul 3, 2013
1 parent 2ebcb55 commit a97d5f4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
21 changes: 21 additions & 0 deletions features/bootstrap/FeatureContext.php
Expand Up @@ -515,5 +515,26 @@ public function outputThe($thing)
echo $this->$thing;
}

/**
* @Then /^the application has a resource for class "([^"]*)", URI "([^"]*)", and priority (\d+)$/
*/
public function theApplicationHasAResourceForClassUriAndPriority($className, $uri, $priority)
{
if (!class_exists($className)) throw new Exception('Class ' . $className . ' does not exist');
$match = '\\' . $className . ' ' . addslashes($uri) . ' ' . $priority;
if (strpos((string) $this->app, $match) === false) {
throw new Exception('Application does not have resource definition "' . $match . '"');
}
}

/**
* @Then /^the application does not have a resource for class "([^"]*)"$/
*/
public function theApplicationDoesNotHaveAResourceForClass($className)
{
preg_match('/' . preg_quote('\\' . $className) . '/', (string) $this->app, $matches);
if ($matches) {
throw new Exception('Application has a resource for class "' . $className . '"');
}
}
}
12 changes: 12 additions & 0 deletions features/issue154.feature
@@ -0,0 +1,12 @@
Feature: Issue 154
In order to make sure issue #154 (https://github.com/peej/tonic/issues/154) is fixed
As a Tonic developer
I want to test the problems in the issue

Scenario: Resource without a URI annotation
Given a resource file "issues/Issue154/*.php" to load
And the request URI of "/issue154"
When I create an application object
And load the resource
Then the application has a resource for class "Issue154\WithAnnotation", URI "/issue154", and priority 1
And the application does not have a resource for class "Issue154\WithoutAnnotation"
11 changes: 11 additions & 0 deletions issues/Issue154/WithAnnotation.php
@@ -0,0 +1,11 @@
<?php
namespace Issue154;

require_once __DIR__ . '/WithoutAnnotation.php';

/**
* @uri /issue154
*/
class WithAnnotation extends WithoutAnnotation {

}
11 changes: 11 additions & 0 deletions issues/Issue154/WithoutAnnotation.php
@@ -0,0 +1,11 @@
<?php
namespace Issue154;

use Tonic\Resource;

/**
* WITHOUT @uri /issue154
*/
class WithoutAnnotation extends Resource {

}

0 comments on commit a97d5f4

Please sign in to comment.