Skip to content

Commit

Permalink
Merge branch 'release/1.1.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
ventrec committed Sep 17, 2019
2 parents 7449efe + b6cb470 commit 8c70010
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sempro/phpunit-pretty-print",
"version": "1.1.10",
"version": "1.1.11",
"description": "Prettify PHPUnit output",
"type": "library",
"license": "MIT",
Expand Down
18 changes: 10 additions & 8 deletions src/PrettyPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ public function endTest(Test $test, float $time): void

// Convert non-breaking method name to camelCase
$testMethodName[1] = str_replace(' ', '', ucwords($testMethodName[1], ' '));

// Convert snakeCase method name to camelCase
$testMethodName[1] = str_replace('_', '', ucwords($testMethodName[1], '_'));

preg_match_all('/((?:^|[A-Z])[a-z]+)/', $testMethodName[1], $matches);
$testNameArray = array_map('strtolower', $matches[0]);

// check if prefix is test remove it
if ($testNameArray[0] === 'test') {
array_shift($testNameArray);
}
preg_match_all('/((?:^|[A-Z])[a-z0-9]+)/', $testMethodName[1], $matches);

// Prepend all numbers with a space
$replaced = preg_replace('/(\d+)/', ' $1', $matches[0]);

$testNameArray = array_map('strtolower', $replaced);

$name = implode(' ', $testNameArray);

// check if prefix is test remove it
$name = preg_replace('/^test /', '', $name, 1);

// Get the data set name
$name = $this->handleDataSetName($name, $testMethodName[1]);

Expand Down
10 changes: 10 additions & 0 deletions tests/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ public function test should convert non breaking spaces to lowercased wo
{
$this->assertTrue(true);
}

public function testCanContain1Or99Numbers()
{
$this->assertTrue(true);
}

public function test123CanStartOrEndWithNumbers456()
{
$this->assertTrue(true);
}
}
14 changes: 14 additions & 0 deletions tests/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ public function testTestNameCanBeNonBreakingSpaced()
$this->assertStringContainsString('✓ should convert non breaking spaces to lowercased words', $lines[11]);
}

public function testTestNameCanContainNumbers()
{
$lines = $this->getOutput();

$this->assertStringContainsString('✓ can contain 1 or 99 numbers', $lines[12]);
}

public function testTestNameCanStartOrEndWithANumber()
{
$lines = $this->getOutput();

$this->assertStringContainsString('✓ 123 can start or end with numbers 456', $lines[13]);
}

private function getOutput(): array
{
$command = [
Expand Down

0 comments on commit 8c70010

Please sign in to comment.