Skip to content

Commit

Permalink
NEW Add tests for Factory::getFriendlySegment
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Jan 11, 2018
1 parent 88fc2c2 commit 43c5e55
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Command/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public function getCommandName(BuildTask $task)
return sprintf('dev:tasks:%s', $segment);
}

/**
* Convert the SilverStripe task names into a common, Symfony console style command with
* dashes between capital letters, backslashes removed and all lowercase
*
* @param string $segment
* @return string
*/
public function getFriendlySegment($segment)
{
// Convert backslashes (from namespaced classes) to dashes
Expand Down
25 changes: 25 additions & 0 deletions tests/Command/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverLeague\Console\Tests\Command;

use SilverLeague\Console\Command\Dev\Tasks\AbstractTaskCommand;
use SilverLeague\Console\Command\Factory;
use SilverLeague\Console\Framework\Scaffold;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Config\Config;
Expand Down Expand Up @@ -84,6 +85,30 @@ public function testGetTaskAsClosure()
$tester->execute([]);
}

/**
* Ensure that SilverStripe task URL segments are made "friendly"
*
* @param string $input
* @param string $expected
* @dataProvider segmentProvider
*/
public function testGetFriendlySegment($input, $expected)
{
$this->assertSame($expected, $this->getFactory()->getFriendlySegment($input));
}

/**
* @return array[]
*/
public function segmentProvider()
{
return [
['SomeTask', 'some'],
['Some\\Namespaced\\TaskName', 'some-namespaced-task-name'],
['CleanupTestDatabasesTask', 'cleanup-test-databases'],
];
}

/**
* Get a Factory to test with
*
Expand Down

0 comments on commit 43c5e55

Please sign in to comment.