Skip to content

Commit

Permalink
Minor fixes for PHPUnit (willdurand#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand authored Apr 12, 2021
1 parent 9ca135c commit bbd05c9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 61 deletions.
14 changes: 4 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
language: php
sudo: required
dist: trusty
group: edge

php:
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm-3.9
- hhvm-3.18
- 7.3
- 7.4
- 8.0

before_script:
- composer install

script: ./vendor/bin/phpunit --coverage-text
script: XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=7.3.0"
},
"autoload": {
"psr-4": { "EmailReplyParser\\": "src/EmailReplyParser" }
Expand All @@ -25,6 +25,6 @@
}
},
"require-dev": {
"phpunit/phpunit": "^4.8.35|^5.7"
"phpunit/phpunit": "^9.5"
}
}
32 changes: 11 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="EmailReplyParser Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/EmailReplyParser/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./src/EmailReplyParser/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="EmailReplyParser Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
56 changes: 28 additions & 28 deletions tests/EmailReplyParser/Tests/Parser/EmailParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EmailParserTest extends TestCase
*/
private $parser;

protected function setUp()
protected function setUp(): void
{
$this->parser = new EmailParser();
}
Expand Down Expand Up @@ -89,10 +89,10 @@ public function testReadsTopPost()
$this->assertTrue($fragments[3]->isHidden());
$this->assertTrue($fragments[4]->isHidden());

$this->assertRegExp('/^Oh thanks.\n\nHaving/', (string) $fragments[0]);
$this->assertRegExp('/^-A/', (string) $fragments[1]);
$this->assertRegExp('/^On [^\:]+\:/', (string) $fragments[2]);
$this->assertRegExp('/^_/', (string) $fragments[4]);
$this->assertMatchesRegularExpression('/^Oh thanks.\n\nHaving/', (string) $fragments[0]);
$this->assertMatchesRegularExpression('/^-A/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^On [^\:]+\:/', (string) $fragments[2]);
$this->assertMatchesRegularExpression('/^_/', (string) $fragments[4]);
}

public function testReadsBottomPost()
Expand All @@ -102,20 +102,20 @@ public function testReadsBottomPost()

$this->assertCount(6, $fragments);
$this->assertEquals('Hi,', (string) $fragments[0]);
$this->assertRegExp('/^On [^\:]+\:/', (string) $fragments[1]);
$this->assertRegExp('/^You can list/', (string) $fragments[2]);
$this->assertRegExp('/^>/', (string) $fragments[3]);
$this->assertRegExp('/^_/', (string) $fragments[5]);
$this->assertMatchesRegularExpression('/^On [^\:]+\:/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^You can list/', (string) $fragments[2]);
$this->assertMatchesRegularExpression('/^>/', (string) $fragments[3]);
$this->assertMatchesRegularExpression('/^_/', (string) $fragments[5]);
}

public function testRecognizesDateStringAboveQuote()
{
$email = $this->parser->parse($this->getFixtures('email_4.txt'));
$fragments = $email->getFragments();

$this->assertRegExp('/^Awesome/', (string) $fragments[0]);
$this->assertRegExp('/^On/', (string) $fragments[1]);
$this->assertRegExp('/Loader/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^Awesome/', (string) $fragments[0]);
$this->assertMatchesRegularExpression('/^On/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/Loader/', (string) $fragments[1]);
}

public function testDoesNotModifyInputString()
Expand All @@ -138,9 +138,9 @@ public function testDealsWithMultilineReplyHeaders()
$email = $this->parser->parse($this->getFixtures('email_6.txt'));
$fragments = $email->getFragments();

$this->assertRegExp('/^I get/', (string) $fragments[0]);
$this->assertRegExp('/^On/', (string) $fragments[1]);
$this->assertRegExp('/Was this/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^I get/', (string) $fragments[0]);
$this->assertMatchesRegularExpression('/^On/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/Was this/', (string) $fragments[1]);
}

public function testEmailItalian()
Expand Down Expand Up @@ -289,7 +289,7 @@ public function testReadsEmailWithCorrectSignature()
$this->assertFalse($fragments[0]->isHidden());
$this->assertTrue($fragments[1]->isHidden());

$this->assertRegExp('/^--\nrick/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^--\nrick/', (string) $fragments[1]);
}

public function testReadsEmailWithSignatureWithNoEmptyLineAbove()
Expand All @@ -308,7 +308,7 @@ public function testReadsEmailWithSignatureWithNoEmptyLineAbove()
$this->assertFalse($fragments[0]->isHidden());
$this->assertTrue($fragments[1]->isHidden());

$this->assertRegExp('/^--\nrick/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^--\nrick/', (string) $fragments[1]);
}

public function testReadsEmailWithCorrectSignatureWithSpace()
Expand All @@ -330,7 +330,7 @@ public function testReadsEmailWithCorrectSignatureWithSpace()
$this->assertFalse($fragments[0]->isHidden());
$this->assertTrue($fragments[1]->isHidden());

$this->assertRegExp('/^-- \nrick/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^-- \nrick/', (string) $fragments[1]);
}

public function testReadsEmailWithCorrectSignatureWithNoEmptyLineWithSpace()
Expand All @@ -352,16 +352,16 @@ public function testReadsEmailWithCorrectSignatureWithNoEmptyLineWithSpace()
$this->assertFalse($fragments[0]->isHidden());
$this->assertTrue($fragments[1]->isHidden());

$this->assertRegExp('/^-- \nrick/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^-- \nrick/', (string) $fragments[1]);
}

public function testOneIsNotOn()
{
$email = $this->parser->parse($this->getFixtures('email_one_is_not_on.txt'));
$fragments = $email->getFragments();

$this->assertRegExp('/One outstanding question/', (string) $fragments[0]);
$this->assertRegExp('/^On Oct 1, 2012/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/One outstanding question/', (string) $fragments[0]);
$this->assertMatchesRegularExpression('/^On Oct 1, 2012/', (string) $fragments[1]);
}

public function testCustomQuoteHeader()
Expand Down Expand Up @@ -411,25 +411,25 @@ public function testVisibleTextSeemsLikeAQuoteHeader1()
{
$email = $this->parser->parse($this->getFixtures('email_19.txt'));
$fragments = $email->getFragments();
$this->assertRegexp('/^On Thursday/', (string) $fragments[0]);
$this->assertRegexp('/^On Dec 16/', (string) $fragments[1]);
$this->assertRegExp('/Was this/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^On Thursday/', (string) $fragments[0]);
$this->assertMatchesRegularExpression('/^On Dec 16/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/Was this/', (string) $fragments[1]);
}

public function testVisibleTextSeemsLikeAQuoteHeader2()
{
$email = $this->parser->parse($this->getFixtures('email_20.txt'));
$fragments = $email->getFragments();
$this->assertRegexp('/^On Thursday/', (string) $fragments[0]);
$this->assertRegexp('/^> On May 17/', (string) $fragments[1]);
$this->assertRegExp('/fix this parsing/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/^On Thursday/', (string) $fragments[0]);
$this->assertMatchesRegularExpression('/^> On May 17/', (string) $fragments[1]);
$this->assertMatchesRegularExpression('/fix this parsing/', (string) $fragments[1]);
}

public function testEmailWithFairAmountOfContent()
{
$email = $this->parser->parse($this->getFixtures('email_21.txt'));
$fragments = $email->getFragments();
$this->assertRegexp('/^On Thursday/', (string) $fragments[0]);
$this->assertMatchesRegularExpression('/^On Thursday/', (string) $fragments[0]);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Fixtures/email_issue_77.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Bonjour Test,

Text paragraph 1


Le paragraphe qui pose problème.

Text paragraph 2


- Le 2021-04-09 23:25, Test a écrit :

0 comments on commit bbd05c9

Please sign in to comment.