Browse Source

Closes #16411. Fix windows tests (#17380)

* Fix `\yiiunit\framework\helpers\ConsoleTest::testErrorSummary`
* Fix `\yiiunit\framework\console\controllers\PHPMessageControllerTest::testRemoveUnusedBehavior`
tags/2.0.22
Alexander Kartavenko 5 years ago committed by Alexander Makarov
parent
commit
c5397f8784
  1. 4
      .appveyor.yml
  2. 1
      framework/console/controllers/MessageController.php
  3. 15
      tests/TestCase.php
  4. 2
      tests/framework/helpers/ConsoleTest.php
  5. 2
      tests/framework/web/ViewTest.php

4
.appveyor.yml

@ -7,10 +7,6 @@ environment:
matrix:
- php_ver: 7.2.4
matrix:
allow_failures:
- php_ver: 7.2.4
cache:
- '%APPDATA%\Composer'
- '%LOCALAPPDATA%\Composer'

1
framework/console/controllers/MessageController.php

@ -903,6 +903,7 @@ EOD;
$categoryFileName = str_replace($dirName, '', $messageFile);
$categoryFileName = ltrim($categoryFileName, DIRECTORY_SEPARATOR);
$category = preg_replace('#\.php$#', '', $categoryFileName);
$category = str_replace(DIRECTORY_SEPARATOR, '/', $category);
if (!in_array($category, $existingCategories, true)) {
unlink($messageFile);

15
tests/TestCase.php

@ -123,6 +123,21 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
}
/**
* Asserts that a haystack contains a needle ignoring line endings.
*
* @param mixed $needle
* @param mixed $haystack
* @param string $message
*/
protected function assertContainsWithoutLE($needle, $haystack, $message = '')
{
$needle = str_replace("\r\n", "\n", $needle);
$haystack = str_replace("\r\n", "\n", $haystack);
$this->assertContains($needle, $haystack, $message);
}
/**
* Invokes a inaccessible method.
* @param $object
* @param $method

2
tests/framework/helpers/ConsoleTest.php

@ -214,7 +214,7 @@ class ConsoleTest extends TestCase
$model->validate(null, false);
$options = ['showAllErrors' => true];
$expectedHtml = "Error message. Here are some chars: < >\nError message. Here are even more chars: \"\"";
$this->assertEquals($expectedHtml, Console::errorSummary($model, $options));
$this->assertEqualsWithoutLE($expectedHtml, Console::errorSummary($model, $options));
}
}

2
tests/framework/web/ViewTest.php

@ -65,7 +65,7 @@ class ViewTest extends TestCase
$view = new View();
$view->registerJsFile('@web/js/somefile.js', ['position' => View::POS_BEGIN]);
$html = $view->render('@yiiunit/data/views/layout.php', ['content' => 'content']);
$this->assertContains('<body>' . PHP_EOL . '<script src="/baseUrl/js/somefile.js"></script>', $html);
$this->assertContainsWithoutLE('<body>' . PHP_EOL . '<script src="/baseUrl/js/somefile.js"></script>', $html);
$view = new View();
$view->registerJsFile('@web/js/somefile.js', ['position' => View::POS_END]);

Loading…
Cancel
Save