Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Php unit windows #5369

Closed
wants to merge 11 commits into from

4 participants

@ThaDafinser

Under windows there are currently a lot of failing tests.

Most problem is \n instead of \r\n.

Some of the problems are fixed with this PR.

@turrsis

@ThaDafinser I use bat file for Windows context menu:
....\php .....\php-cs-fixer.phar fix %1 --level=psr2

@ThaDafinser

@turrsis is the failing because of the formatting? Oo

@ThaDafinser

Ahhh better =)

@ThaDafinser

@turrsis thanks for the hint...

There are still unresolved issues for testing under windows, but many are fixed with this PR

@Maks3w Maks3w commented on the diff
tests/ZendTest/Feed/Reader/Entry/CommonTest.php
@@ -72,7 +72,9 @@ public function testSaveXmlOutputsXmlStringForEntry()
file_get_contents($this->feedSamplePath.'/atom.xml')
);
$entry = $feed->current();
- $this->assertEquals($entry->saveXml(), file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml'));
+ $expected = file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml');
@Maks3w Collaborator
Maks3w added a note

what about DIRECTORY_SEPARATOR

PHP handles paths converting itself. The DIRECTORY_SEPERATOR is only needed when it comes to comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Maks3w Maks3w commented on the diff
tests/ZendTest/Feed/Reader/Feed/CommonTest.php
@@ -66,7 +66,9 @@ public function testSaveXmlOutputsXmlStringForFeed()
$feed = Reader\Reader::importString(
file_get_contents($this->feedSamplePath.'/atom.xml')
);
- $this->assertEquals($feed->saveXml(), file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml'));
+ $expected = file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml');
@Maks3w Collaborator
Maks3w added a note

here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@turrsis

Nothing of this is not resolve the problems.
ZendTest/Feed/, ZendTest/Db/, ZendTest/Crypt/, ZendTest/Config/ is already ok - no changes need.
ZendTest\Console\Prompt\NumberTest::testCanReadNumberOnMultilign - is failed.

@ThaDafinser To my mind - you should check CrLf settings for your git.

@turrsis

@ThaDafinser Comments on @Maks3w still actual.

@ThaDafinser

@turrsis i'm really sorry, but i have a lot of problems understanding your sentences.
What do you mean with "Nothing of this is not resolve the problems." - Do ALL problems still exist for you? Or are there still other issues? Because i have not fixed the complete testing suite.

What is with the comments from @Maks3w ? Do you have problems with '/' for file loading in your ENV? It should be only a problem when it comes to comparison

The EOL in my ENV is \r\n (but that should be fixed by the php-cs-fixer or not?)

@turrsis

@ThaDafinser try to revert you changes, change CrLf settings for your git, clone zf2 again to new folder, run tests - ZendTest/Feed/, ZendTest/Db/, ZendTest/Crypt/, ZendTest/Config/ will ok. See comments on #5163

@turrsis

Sorry - my previous comment is realy hard for undertanding.
1. psr-2 - All PHP files MUST use the Unix LF (linefeed) line ending.
2. to my mind - using str_replace("\r\n", "\n", $expected); is not good practic because in #5163 using 50 replacements and this not solve all problems.
After Ocramius's comment (#5163 (comment)) i reload repository with correct Unix LineFeed - and most problem with EOL was resolved.
3. ZendTest\Crypt\Key\Derivation\ScryptTest is failed on Windows when Unix LF is using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  tests/ZendTest/Config/Writer/XmlTest.php
@@ -42,6 +42,7 @@ public function testToString()
ECS;
+ $expected = str_replace("\r\n", "\n", $expected);
$this->assertEquals($expected, $configString);
}
@@ -78,6 +79,7 @@ public function testSectionsToString()
ECS;
+ $expected = str_replace("\r\n", "\n", $expected);
$this->assertEquals($expected, $configString);
}
}
View
18 tests/ZendTest/Console/Prompt/NumberTest.php
@@ -48,8 +48,8 @@ public function testCanReadNumber()
public function testCanReadNumberOnMultilign()
{
- fwrite($this->adapter->stream, "a\n");
- fwrite($this->adapter->stream, "123\n");
+ fwrite($this->adapter->stream, "a" . PHP_EOL);
+ fwrite($this->adapter->stream, "123" . PHP_EOL);
rewind($this->adapter->stream);
$this->adapter->autoRewind = false;
@@ -64,8 +64,8 @@ public function testCanReadNumberOnMultilign()
public function testCanNotReadFloatByDefault()
{
- fwrite($this->adapter->stream, "1.23\n");
- fwrite($this->adapter->stream, "123\n");
+ fwrite($this->adapter->stream, "1.23" . PHP_EOL);
+ fwrite($this->adapter->stream, "123" . PHP_EOL);
rewind($this->adapter->stream);
$this->adapter->autoRewind = false;
@@ -80,8 +80,8 @@ public function testCanNotReadFloatByDefault()
public function testCanForceToReadFloat()
{
- fwrite($this->adapter->stream, "1.23\n");
- fwrite($this->adapter->stream, "123\n");
+ fwrite($this->adapter->stream, "1.23" . PHP_EOL);
+ fwrite($this->adapter->stream, "123" . PHP_EOL);
rewind($this->adapter->stream);
$this->adapter->autoRewind = false;
@@ -96,9 +96,9 @@ public function testCanForceToReadFloat()
public function testCanDefineAMax()
{
- fwrite($this->adapter->stream, "1\n");
- fwrite($this->adapter->stream, "11\n");
- fwrite($this->adapter->stream, "6\n");
+ fwrite($this->adapter->stream, "1" . PHP_EOL);
+ fwrite($this->adapter->stream, "11" . PHP_EOL);
+ fwrite($this->adapter->stream, "6" . PHP_EOL);
rewind($this->adapter->stream);
$this->adapter->autoRewind = false;
View
14 tests/ZendTest/Crypt/Key/Derivation/ScryptTest.php
@@ -49,12 +49,12 @@ public function testVectorSalsa208Core()
}
$salsa20 = self::getMethod($salsaAlg);
$obj = $this->getMockForAbstractClass('Zend\Crypt\Key\Derivation\Scrypt');
- $input = self::hex2bin(str_replace(array(' ',"\n"),'',$hexInput));
+ $input = self::hex2bin(str_replace(array(' ',PHP_EOL),'',$hexInput));
$result = $salsa20->invokeArgs($obj, array($input));
$this->assertEquals(64, strlen($input), 'Input must be a string of 64 bytes');
$this->assertEquals(64, strlen($result), 'Output must be a string of 64 bytes');
- $this->assertEquals(str_replace(array(' ',"\n"),'',$hexOutput), bin2hex($result));
+ $this->assertEquals(str_replace(array(' ',PHP_EOL),'',$hexOutput), bin2hex($result));
}
/**
* Test vector of Scrypt BlockMix
@@ -85,10 +85,10 @@ public function testVectorScryptBlockMix()
$blockMix = self::getMethod('scryptBlockMix');
$obj = $this->getMockForAbstractClass('Zend\Crypt\Key\Derivation\Scrypt');
- $input = self::hex2bin(str_replace(array(' ',"\n"), '', $hexInput));
+ $input = self::hex2bin(str_replace(array(' ',PHP_EOL), '', $hexInput));
$result = $blockMix->invokeArgs($obj, array($input, 1));
- $this->assertEquals(str_replace(array(' ',"\n"),'',$hexOutput), bin2hex($result));
+ $this->assertEquals(str_replace(array(' ',PHP_EOL),'',$hexOutput), bin2hex($result));
}
/**
@@ -119,10 +119,10 @@ public function testVectorScryptROMix()
$roMix = self::getMethod('scryptROMix');
$obj = $this->getMockForAbstractClass('Zend\Crypt\Key\Derivation\Scrypt');
- $input = self::hex2bin(str_replace(array(' ',"\n"), '', $hexInput));
+ $input = self::hex2bin(str_replace(array(' ',PHP_EOL), '', $hexInput));
$result = $roMix->invokeArgs($obj, array($input, 16, 1));
- $this->assertEquals(str_replace(array(' ',"\n"),'',$hexOutput), bin2hex($result));
+ $this->assertEquals(str_replace(array(' ',PHP_EOL),'',$hexOutput), bin2hex($result));
}
@@ -140,7 +140,7 @@ public function testVectorScrypt()
$result = Scrypt::calc('', '', 16, 1, 1, 64);
$this->assertEquals(64, strlen($result));
- $this->assertEquals(str_replace(array(' ',"\n"),'',$hexOutput), bin2hex($result));
+ $this->assertEquals(str_replace(array(' ',PHP_EOL),'',$hexOutput), bin2hex($result));
}
/**
View
1  tests/ZendTest/Db/Sql/Ddl/AlterTableTest.php
@@ -103,6 +103,7 @@ public function testGetSqlString()
DROP CONSTRAINT "my_index"
EOS;
+ $expected = str_replace("\r\n", "\n", $expected);
$this->assertEquals($expected, $at->getSqlString());
}
}
View
4 tests/ZendTest/Feed/Reader/Entry/CommonTest.php
@@ -72,7 +72,9 @@ public function testSaveXmlOutputsXmlStringForEntry()
file_get_contents($this->feedSamplePath.'/atom.xml')
);
$entry = $feed->current();
- $this->assertEquals($entry->saveXml(), file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml'));
+ $expected = file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml');
@Maks3w Collaborator
Maks3w added a note

what about DIRECTORY_SEPARATOR

PHP handles paths converting itself. The DIRECTORY_SEPERATOR is only needed when it comes to comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $expected = str_replace("\r\n", "\n", $expected);
+ $this->assertEquals($expected, $entry->saveXml());
}
public function testGetsNamedExtension()
View
4 tests/ZendTest/Feed/Reader/Feed/CommonTest.php
@@ -66,7 +66,9 @@ public function testSaveXmlOutputsXmlStringForFeed()
$feed = Reader\Reader::importString(
file_get_contents($this->feedSamplePath.'/atom.xml')
);
- $this->assertEquals($feed->saveXml(), file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml'));
+ $expected = file_get_contents($this->feedSamplePath.'/atom_rewrittenbydom.xml');
@Maks3w Collaborator
Maks3w added a note

here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $expected = str_replace("\r\n", "\n", $expected);
+ $this->assertEquals($expected, $feed->saveXml());
}
public function testGetsNamedExtension()
View
24 tests/ZendTest/Feed/Reader/Integration/PodcastRss2Test.php
@@ -96,10 +96,12 @@ public function testGetsDescription()
$feed = Reader\Reader::importString(
file_get_contents($this->feedSamplePath)
);
- $this->assertEquals('All About Everything is a show about everything.
+ $expected = 'All About Everything is a show about everything.
Each week we dive into any subject known to man and talk
about it as much as we can. Look for our Podcast in the
- iTunes Store', $feed->getDescription());
+ iTunes Store';
+ $expected = str_replace("\r\n", "\n", $expected);
+ $this->assertEquals($expected, $feed->getDescription());
}
public function testGetsLanguage()
@@ -205,8 +207,10 @@ public function testGetsSubtitle()
file_get_contents($this->feedSamplePath)
);
$entry = $feed->current();
- $this->assertEquals('A short primer on table spices
- ', $entry->getSubtitle());
+ $expected = 'A short primer on table spices
+ ';
+ $expected = str_replace("\r\n", "\n", $expected);
+ $this->assertEquals($expected, $entry->getSubtitle());
}
public function testGetsSummary()
@@ -215,10 +219,12 @@ public function testGetsSummary()
file_get_contents($this->feedSamplePath)
);
$entry = $feed->current();
- $this->assertEquals('This week we talk about salt and pepper
+ $expected = 'This week we talk about salt and pepper
shakers, comparing and contrasting pour rates,
construction materials, and overall aesthetics. Come and
- join the party!', $entry->getSummary());
+ join the party!';
+ $expected = str_replace("\r\n", "\n", $expected);
+ $this->assertEquals($expected, $entry->getSummary());
}
public function testGetsDuration()
@@ -236,8 +242,10 @@ public function testGetsKeywords()
file_get_contents($this->feedSamplePath)
);
$entry = $feed->current();
- $this->assertEquals('salt, pepper, shaker, exciting
- ', $entry->getKeywords());
+ $expected = 'salt, pepper, shaker, exciting
+ ';
+ $expected = str_replace("\r\n", "\n", $expected);
+ $this->assertEquals($expected, $entry->getKeywords());
}
public function testGetsEntryEncoding()
View
5 tests/ZendTest/Feed/Reader/ReaderTest.php
@@ -264,6 +264,11 @@ public function testRegistersUserExtension()
$this->assertTrue(Reader\Reader::isRegistered('JungleBooks'));
}
+ /**
+ * This test is failing on windows:
+ * Failed asserting that exception of type "Zend\Feed\Reader\Exception\RuntimeException" matches expected exception "Zend\Feed\Reader\Exception\InvalidArgumentException". Message was: "DOMDocument cannot parse XML: Entity 'discloseInfo' failed to parse".
+ * @todo why is the assertEquals commented out?
+ */
public function testXxePreventionOnFeedParsing()
{
$this->setExpectedException('Zend\Feed\Reader\Exception\InvalidArgumentException');
View
2  tests/ZendTest/Feed/Writer/FeedTest.php
@@ -1021,6 +1021,7 @@ public function testExportRss()
EOT;
$feed = str_replace('%version%', Version::VERSION, $feed);
+ $feed = str_replace("\r\n", "\n", $feed);
$this->assertEquals($feed, $export);
}
@@ -1042,6 +1043,7 @@ public function testExportRssIgnoreExceptions()
EOT;
$feed = str_replace('%version%', Version::VERSION, $feed);
+ $feed = str_replace("\r\n", "\n", $feed);
$this->assertEquals($feed, $export);
}
View
2  tests/ZendTest/Filter/Compress/ZipTest.php
@@ -22,7 +22,7 @@ public function setUp()
$this->markTestSkipped('This adapter needs the zip extension');
}
- $this->tmp = sys_get_temp_dir() . '/' . str_replace('\\', '_', __CLASS__);
+ $this->tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . str_replace('\\', '_', __CLASS__);
$files = array(
$this->tmp . '/compressed.zip',
View
4 tests/ZendTest/Filter/File/RenameTest.php
@@ -491,7 +491,7 @@ public function testGetRandomizedFile()
$filter->getFile()
);
$fileNoExt = $this->_filesPath . 'newfile';
- $this->assertRegExp('#' . $fileNoExt . '_.{13}\.xml#', $filter->getNewName($this->_oldFile));
+ $this->assertRegExp('#' . str_replace('\\', '\\\\', $fileNoExt) . '_.{13}\.xml#', $filter->getNewName($this->_oldFile));
}
/**
@@ -515,7 +515,7 @@ public function testGetRandomizedFileWithoutExtension()
)),
$filter->getFile()
);
- $this->assertRegExp('#' . $fileNoExt . '_.{13}#', $filter->getNewName($this->_oldFile));
+ $this->assertRegExp('#' . str_replace('\\', '\\\\', $fileNoExt) . '_.{13}#', $filter->getNewName($this->_oldFile));
}
/**
View
22 tests/ZendTest/Filter/File/RenameUploadTest.php
@@ -66,9 +66,9 @@ public function setUp()
mkdir($this->_filesPath);
mkdir($this->_newDir);
- $this->_oldFile = $this->_filesPath . '/testfile.txt';
- $this->_newFile = $this->_filesPath . '/newfile.xml';
- $this->_newDirFile = $this->_newDir . '/testfile.txt';
+ $this->_oldFile = $this->_filesPath . DIRECTORY_SEPARATOR . 'testfile.txt';
+ $this->_newFile = $this->_filesPath . DIRECTORY_SEPARATOR . 'newfile.xml';
+ $this->_newDirFile = $this->_newDir . DIRECTORY_SEPARATOR . 'testfile.txt';
touch($this->_oldFile);
}
@@ -245,18 +245,18 @@ public function testCannotOverwriteExistingFile()
*/
public function testGetRandomizedFile()
{
- $fileNoExt = $this->_filesPath . '/newfile';
+ $fileNoExt = $this->_filesPath . DIRECTORY_SEPARATOR . 'newfile';
$filter = new RenameUploadMock(array(
'target' => $this->_newFile,
'randomize' => true,
));
- $this->assertRegExp('#' . $fileNoExt . '_.{13}\.xml#', $filter($this->_oldFile));
+ $this->assertRegExp('#' . str_replace('\\', '\\\\', $fileNoExt) . '_.{13}\.xml#', $filter($this->_oldFile));
}
public function testGetFileWithOriginalExtension()
{
- $fileNoExt = $this->_filesPath . '/newfile';
+ $fileNoExt = $this->_filesPath . DIRECTORY_SEPARATOR . 'newfile';
$filter = new RenameUploadMock(array(
'target' => $this->_newFile,
'use_upload_extension' => true,
@@ -266,14 +266,14 @@ public function testGetFileWithOriginalExtension()
$oldFilePathInfo = pathinfo($this->_oldFile);
$this->assertRegExp(
- '#' . $fileNoExt . '.'.$oldFilePathInfo['extension'].'#',
+ '#' . str_replace('\\', '\\\\', $fileNoExt) . '.'.$oldFilePathInfo['extension'].'#',
$filter($this->_oldFile)
);
}
public function testGetRandomizedFileWithOriginalExtension()
{
- $fileNoExt = $this->_filesPath . '/newfile';
+ $fileNoExt = $this->_filesPath . DIRECTORY_SEPARATOR . 'newfile';
$filter = new RenameUploadMock(array(
'target' => $this->_newFile,
'use_upload_extension' => true,
@@ -283,7 +283,7 @@ public function testGetRandomizedFileWithOriginalExtension()
$oldFilePathInfo = pathinfo($this->_oldFile);
$this->assertRegExp(
- '#' . $fileNoExt . '_.{13}\.'.$oldFilePathInfo['extension'].'#',
+ '#' . str_replace('\\', '\\\\', $fileNoExt) . '_.{13}\.'.$oldFilePathInfo['extension'].'#',
$filter($this->_oldFile)
);
}
@@ -293,13 +293,13 @@ public function testGetRandomizedFileWithOriginalExtension()
*/
public function testGetRandomizedFileWithoutExtension()
{
- $fileNoExt = $this->_filesPath . '/newfile';
+ $fileNoExt = $this->_filesPath . DIRECTORY_SEPARATOR . 'newfile';
$filter = new RenameUploadMock(array(
'target' => $fileNoExt,
'randomize' => true,
));
- $this->assertRegExp('#' . $fileNoExt . '_.{13}#', $filter($this->_oldFile));
+ $this->assertRegExp('#' . str_replace('\\', '\\\\', $fileNoExt) . '_.{13}#', $filter($this->_oldFile));
}
/**
Something went wrong with that request. Please try again.