Skip to content

Commit

Permalink
Added unit test that checks changelog formatting [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa authored and samdark committed Dec 13, 2017
1 parent 713529e commit 9903046
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Yii Framework 2 Change Log
- Enh #15221: Improved the `help/list-action-options` console command output for command options without a description (brandonkelly)
- Enh #15332: Always check for availability of `openssl_pseudo_random_bytes`, even if LibreSSL is available (sammousa)
- Enh #15335: Added `FileHelper::unlink()` that works well under all OSes (samdark)

- Enh #15340: Test CHANGELOG.md for valid format (sammousa)

2.0.13.1 November 14, 2017
--------------------------
Expand Down
54 changes: 54 additions & 0 deletions tests/framework/ChangeLogTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yiiunit\framework;

use yiiunit\TestCase;

/**
* ChangeLogTest.
* @group base
*/
class ChangeLogTest extends TestCase
{
public function changeProvider()
{

$lines = explode("\n", file_get_contents(__DIR__ . '/../../framework/CHANGELOG.md'));

// Don't check last 1500 lines, they are old and often don't obey the standard.
$lastIndex = count($lines) - 1500;
$result = [];
foreach($lines as $i => $line) {
if (strncmp('- ', $line, 2) === 0) {
$result[] = [$line];
}

if ($i > $lastIndex) {
break;
}
}
return $result;
}

/**
* @dataProvider changeProvider
*/
public function testContributorLine($line)
{
/**
* Each change line is tested for:
* - Starts with "- "
* - Has a type: Bug, Enh, Chg, New
* - Has a number formatted like #12345
* - Description starts after ": "
* - Description ends without a "."
* - Line ends with contributor name between "(" and ")".
*/
$this->assertRegExp('/- (Bug|Enh|Chg|New)( #\d+(, #\d+)*)?: .*[^.] \(.*\)$/', $line);
}
}

0 comments on commit 9903046

Please sign in to comment.