From f2fe6c4b24a053c0e609dcdf2b5ef86be5edcea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Fri, 15 Mar 2019 14:43:10 +0100 Subject: [PATCH 01/16] Fix text output iteration over Beholder results --- Jyxo/Beholder/Output/TextOutput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jyxo/Beholder/Output/TextOutput.php b/Jyxo/Beholder/Output/TextOutput.php index 2342fda..4ecde5c 100644 --- a/Jyxo/Beholder/Output/TextOutput.php +++ b/Jyxo/Beholder/Output/TextOutput.php @@ -47,7 +47,7 @@ public function __toString(): string $return .= sprintf("%-9s %10s %-10s %-7s %-35s %s\n", 'Run Order', 'Duration', 'Ident', 'Status', 'Test Name', 'Description'); - foreach ($this->testsData as $data) { + foreach ($this->result->getTestsData() as $data) { $return .= sprintf("%9d %9.2fs %-10s %-7s %-35s %s\n", $data['order'], $data['duration'], From f801232c5c62e542f34c8ae4ecdab6c9cb4a0fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Fri, 15 Mar 2019 15:45:08 +0100 Subject: [PATCH 02/16] Warn about missing tidy extension; skip test --- Jyxo/Html.php | 5 +++++ tests/Jyxo/HtmlTest.php | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Jyxo/Html.php b/Jyxo/Html.php index 8c41e41..7b622cd 100644 --- a/Jyxo/Html.php +++ b/Jyxo/Html.php @@ -80,6 +80,11 @@ public static function repair(string $html): string // 'drop-proprietary-attributes' => true, // Removes proprietary attributes (it would remove e.g. the background attribute) // 'drop-font-tags' => true // Removes and
tags ]; + + if (!function_exists('\tidy_repair_string')) { + throw new \Jyxo\Exception('Missing "tidy" extension.'); + } + $html = tidy_repair_string($html, $config, 'utf8'); // Removes namespace generated by MS Word diff --git a/tests/Jyxo/HtmlTest.php b/tests/Jyxo/HtmlTest.php index 5245552..c678a58 100644 --- a/tests/Jyxo/HtmlTest.php +++ b/tests/Jyxo/HtmlTest.php @@ -71,6 +71,10 @@ public function testIs() */ public function testRepair() { + if (!function_exists('\tidy_repair_string')) { + $this->markTestSkipped('Skipping, missing "tidy" extension.'); + } + $this->assertStringEqualsFile( $this->filePath . '/repair-expected.html', Html::repair(file_get_contents($this->filePath . '/repair.html')) From 6a29cf6d6b9f95e4117449531775048894d9d25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Fri, 15 Mar 2019 15:46:53 +0100 Subject: [PATCH 03/16] Use composer autoloading for tests --- composer.json | 6 +++++- tests/bootstrap.php | 15 +-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index b87c234..a81f41f 100644 --- a/composer.json +++ b/composer.json @@ -21,11 +21,15 @@ "ext-curl": "To use Jyxo\\Rpc client/server or Jyxo\\Webdav client", "ext-json": "To use Jyxo\\Rpc\\Json client/server or Jyxo\\FirePHP logger", "ext-xmlrpc": "To use Jyxo\\Rpc\\Xml client/server", - "ext-imap": "To use Jyxo\\Mail\\Parser" + "ext-imap": "To use Jyxo\\Mail\\Parser", + "ext-tidy": "To use Jyxo\\Html extended capabilities" }, "autoload": { "psr-4": { "Jyxo\\": ["Jyxo/"] } }, + "autoload-dev": { + "psr-4": { "Jyxo\\": ["tests/Jyxo"] } + }, "config": { "bin-dir": "bin", "optimize-autoloader": true, diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 68255a9..4c9fc18 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,20 +14,7 @@ // Because of SessionTest session_start(); -// Autoload -spl_autoload_register(function($className) { - if (strpos($className, 'Jyxo') !== 0) { - return; - } - - $file = str_replace('\\', '/', $className) . '.php'; - foreach ([realpath(__DIR__ . '/..'), __DIR__] as $dir) { - $filePath = $dir . '/' . $file; - if (false !== stream_resolve_include_path($filePath)) { - require_once $filePath; - } - } -}); +require __DIR__ . '/../vendor/autoload.php'; // File path define('DIR_FILES', __DIR__ . '/files'); From f76b2542100d7d75fa1330a701611725cdc159c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Fri, 15 Mar 2019 15:47:52 +0100 Subject: [PATCH 04/16] Port in Memchached beholder test case has to be an integer --- tests/Jyxo/Beholder/TestCase/MemcachedTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Jyxo/Beholder/TestCase/MemcachedTest.php b/tests/Jyxo/Beholder/TestCase/MemcachedTest.php index 78296cc..b7cedd7 100644 --- a/tests/Jyxo/Beholder/TestCase/MemcachedTest.php +++ b/tests/Jyxo/Beholder/TestCase/MemcachedTest.php @@ -41,7 +41,7 @@ public function testConnectionFailure() } $ip = '127.0.0.1'; - $port = '12345'; + $port = 12345; $test = new Memcached('Memcached', $ip, $port); // @ on purpose From 61fd1c15198eca0ecfae2e9d82cf87a90144ad65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Fri, 15 Mar 2019 15:59:12 +0100 Subject: [PATCH 05/16] Fix cookie magic Time property format --- tests/Jyxo/Time/TimeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Jyxo/Time/TimeTest.php b/tests/Jyxo/Time/TimeTest.php index 5a91a1f..6129f78 100644 --- a/tests/Jyxo/Time/TimeTest.php +++ b/tests/Jyxo/Time/TimeTest.php @@ -176,7 +176,7 @@ public function testMagicGet() $this->assertEquals('2009-10-10T00:00:00+0700', $time->sql); $this->assertEquals('Sat, 10 Oct 09 00:00:00 +0700', $time->email); $this->assertEquals('2009-10-10T00:00:00+07:00', $time->web); - $this->assertEquals('Saturday, 10-Oct-2009 00:00:00 GMT-7', $time->cookie); + $this->assertEquals('Saturday, 10-Oct-2009 00:00:00 +07', $time->cookie); $this->assertEquals('Sat, 10 Oct 2009 00:00:00 +0700', $time->rss); $this->assertEquals('1255107600', $time->unix); $this->assertEquals('Fri, 09 Oct 2009 17:00:00 GMT', $time->http); From a0c361ef8c53f841ddbebdbce28b6f9d21dfd497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 14:06:13 +0100 Subject: [PATCH 06/16] Add travis build --- .travis.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b1115f3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: php + +dist: xenial + +group: edge + +php: + - 7.0 + - 7.1 + - 7.2 + - 7.3 + - nightly + +matrix: + + include: + + allow_failures: + - php: nightly + +install: + - composer self-update + - | + if [[ "${TRAVIS_PHP_VERSION:0:7}" == "nightly" ]]; then + composer install --ignore-platform-reqs + else + composer install + fi + +script: + bin/phpunit From 687f57b23b53aa714e64f456c5ef52135e57ed69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 14:11:11 +0100 Subject: [PATCH 07/16] Remove unnecessary session start call --- tests/bootstrap.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4c9fc18..7c225f0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,9 +11,6 @@ * https://github.com/jyxo/php/blob/master/license.txt */ -// Because of SessionTest -session_start(); - require __DIR__ . '/../vendor/autoload.php'; // File path From c7cc5d90a762d7ec76a217f9adec00d802651d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 14:17:39 +0100 Subject: [PATCH 08/16] Split Mail sender to a unit and integrationt est --- tests/Jyxo/Mail/EmailTestHelpers.php | 43 ++++++++++++ tests/Jyxo/Mail/SenderIntegrationTest.php | 84 +++++++++++++++++++++++ tests/Jyxo/Mail/SenderTest.php | 34 +-------- 3 files changed, 129 insertions(+), 32 deletions(-) create mode 100644 tests/Jyxo/Mail/EmailTestHelpers.php create mode 100644 tests/Jyxo/Mail/SenderIntegrationTest.php diff --git a/tests/Jyxo/Mail/EmailTestHelpers.php b/tests/Jyxo/Mail/EmailTestHelpers.php new file mode 100644 index 0000000..e797c94 --- /dev/null +++ b/tests/Jyxo/Mail/EmailTestHelpers.php @@ -0,0 +1,43 @@ +setSubject('Novinky září 2009 ... a kreslící soutěž') + ->setFrom(new Email\Address('blog-noreply@blog.cz', 'Blog.cz')) + ->addTo(new Email\Address('test@blog.cz', 'Test Test')) + ->setBody(new Email\Body(\Jyxo\Html::toText($this->content))); + + return $email; + } + + /** + * Compares the actual and expected result. + * + * @param string $file FileAttachment with the expected result + * @param \Jyxo\Mail\Sender\Result $result + */ + private function assertResult(string $file, \Jyxo\Mail\Sender\Result $result) + { + $expected = file_get_contents($this->filePath . '/' . $file); + + // Replacing some headers that are created dynamically + $expected = preg_replace('~====b1[a-z0-9]{32}====~', '====b1' . substr($result->messageId, 0, 32) . '====', $expected); + $expected = preg_replace('~====b2[a-z0-9]{32}====~', '====b2' . substr($result->messageId, 0, 32) . '====', $expected); + $expected = preg_replace("~Date: [^\n]+~", 'Date: ' . $result->datetime->email, $expected); + $expected = preg_replace('~Message-ID: <[^>]+>~', 'Message-ID: <' . $result->messageId . '>', $expected); + + $this->assertEquals($expected, $result->source, sprintf('Failed test for file %s.', $file)); + } + +} diff --git a/tests/Jyxo/Mail/SenderIntegrationTest.php b/tests/Jyxo/Mail/SenderIntegrationTest.php new file mode 100644 index 0000000..63d0953 --- /dev/null +++ b/tests/Jyxo/Mail/SenderIntegrationTest.php @@ -0,0 +1,84 @@ +filePath = DIR_FILES . '/mail'; + $this->content = file_get_contents($this->filePath . '/email.html'); + } + + /** + * Tests sending using the mail() function. + */ + public function testSendMail() + { + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $this->markTestSkipped('Skipped on Windows'); + } + + $sender = new Sender(); + $sender->setEmail($this->getEmail()); + $result = $sender->send(Sender::MODE_MAIL); + $this->assertResult('sender-type-simple-text.eml', $result); + } + + /** + * Tests sending using a SMTP server. + */ + public function testSendSmtp() + { + // Skips the test if no smtp connection is set + if (empty($GLOBALS['smtp'])) { + $this->markTestSkipped('Smtp host not set'); + } + + $sender = new Sender(); + $sender->setEmail($this->getEmail()) + ->setSmtp($GLOBALS['smtp']); + $result = $sender->send(Sender::MODE_SMTP); + $this->assertResult('sender-type-simple-text.eml', $result); + } + +} diff --git a/tests/Jyxo/Mail/SenderTest.php b/tests/Jyxo/Mail/SenderTest.php index 478d4f3..c530608 100644 --- a/tests/Jyxo/Mail/SenderTest.php +++ b/tests/Jyxo/Mail/SenderTest.php @@ -23,6 +23,8 @@ */ class SenderTest extends \PHPUnit_Framework_TestCase { + use EmailTestHelpers; + /** * FileAttachment path. * @@ -46,38 +48,6 @@ protected function setUp() $this->content = file_get_contents($this->filePath . '/email.html'); } - /** - * Tests sending using the mail() function. - */ - public function testSendMail() - { - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $this->markTestSkipped('Skipped on Windows'); - } - - $sender = new Sender(); - $sender->setEmail($this->getEmail()); - $result = $sender->send(Sender::MODE_MAIL); - $this->assertResult('sender-type-simple-text.eml', $result); - } - - /** - * Tests sending using a SMTP server. - */ - public function testSendSmtp() - { - // Skips the test if no smtp connection is set - if (empty($GLOBALS['smtp'])) { - $this->markTestSkipped('Smtp host not set'); - } - - $sender = new Sender(); - $sender->setEmail($this->getEmail()) - ->setSmtp($GLOBALS['smtp']); - $result = $sender->send(Sender::MODE_SMTP); - $this->assertResult('sender-type-simple-text.eml', $result); - } - /** * Tests possible sending errors. */ From 81d704146d84f9beac37de0a8d721f23fb125574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 14:18:11 +0100 Subject: [PATCH 09/16] Remove duplicate skip in Memcached Beholder test --- tests/Jyxo/Beholder/TestCase/MemcachedTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Jyxo/Beholder/TestCase/MemcachedTest.php b/tests/Jyxo/Beholder/TestCase/MemcachedTest.php index b7cedd7..334fdfd 100644 --- a/tests/Jyxo/Beholder/TestCase/MemcachedTest.php +++ b/tests/Jyxo/Beholder/TestCase/MemcachedTest.php @@ -36,10 +36,6 @@ public function setUp() */ public function testConnectionFailure() { - if (!class_exists('Memcached')) { - $this->markTestSkipped('Memcached not set'); - } - $ip = '127.0.0.1'; $port = 12345; From ed29a49cbd13584d0b0019ac2ea247f11d4e9b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 14:19:18 +0100 Subject: [PATCH 10/16] Beholder memcache test: Change connection error test string --- tests/Jyxo/Beholder/TestCase/MemcachedTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Jyxo/Beholder/TestCase/MemcachedTest.php b/tests/Jyxo/Beholder/TestCase/MemcachedTest.php index 334fdfd..74d28f3 100644 --- a/tests/Jyxo/Beholder/TestCase/MemcachedTest.php +++ b/tests/Jyxo/Beholder/TestCase/MemcachedTest.php @@ -43,7 +43,7 @@ public function testConnectionFailure() // @ on purpose $result = @$test->run(); $this->assertEquals(\Jyxo\Beholder\Result::FAILURE, $result->getStatus()); - $this->assertEquals(sprintf('Connection error %s:%s', gethostbyaddr($ip), $port), $result->getDescription()); + $this->assertEquals(sprintf('Write error %s:%s', gethostbyaddr($ip), $port), $result->getDescription()); } /** From ffbe98621b7ec644a6a2a211dc886ae669393380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 14:23:55 +0100 Subject: [PATCH 11/16] Exclude integration tests in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b1115f3..13399a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,4 +28,4 @@ install: fi script: - bin/phpunit + bin/phpunit tests --exclude-group=integration From 706a059dddbe2afb88091575ec2631324ab3526e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 16:23:01 +0100 Subject: [PATCH 12/16] Set default timezone for tests --- tests/bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7c225f0..9a142c7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,5 +13,7 @@ require __DIR__ . '/../vendor/autoload.php'; +date_default_timezone_set('Europe/Prague'); + // File path define('DIR_FILES', __DIR__ . '/files'); From 9bacb9e9881c7ead14182f7dea1ac59b31f12b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 16:26:11 +0100 Subject: [PATCH 13/16] Add cs lanuage pack to travis build --- .travis.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13399a3..9d4bee9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,17 +4,20 @@ dist: xenial group: edge +addons: + apt: + packages: + - language-pack-cs + php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 + - '7.0' + - '7.1' + - '7.2' + - '7.3' - nightly matrix: - include: - allow_failures: - php: nightly From 52635e782daf9c06a07618c26e5be4f89227bf90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 16:32:59 +0100 Subject: [PATCH 14/16] Charset: change expectations for fixUtf --- tests/Jyxo/CharsetTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Jyxo/CharsetTest.php b/tests/Jyxo/CharsetTest.php index 61fa22e..2dbba0c 100644 --- a/tests/Jyxo/CharsetTest.php +++ b/tests/Jyxo/CharsetTest.php @@ -62,7 +62,7 @@ public function testFixUtf() $this->assertEquals('žluťoučký kůň pěl ďábelské ódy', Charset::fixUtf('žluťoučký kůň pěl ďábelské ódy')); $this->assertEquals('Государственный гимн Российской Федерации', Charset::fixUtf('Государственный гимн Российской Федерации')); - $this->assertEquals('', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/cp1250.txt'))); - $this->assertEquals('', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/iso-8859-2.txt'))); + $this->assertEquals('luouk k pern pl belsk dy', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/cp1250.txt'))); + $this->assertEquals('luouk k pern pl belsk dy', Charset::fixUtf(file_get_contents(DIR_FILES . '/charset/iso-8859-2.txt'))); } } From d21df0e27fcc99ab7dc876c24c205841c8c827dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 16:35:13 +0100 Subject: [PATCH 15/16] Set up travis notifications --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9d4bee9..9080ad9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,3 +32,8 @@ install: script: bin/phpunit tests --exclude-group=integration + +notifications: + email: + on_success: change + on_failure: always From 34e84a3cd24310eee82bce97f8e69d49315da258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Sat, 16 Mar 2019 16:36:41 +0100 Subject: [PATCH 16/16] Do not test PHP 7.2+ until Spl\Object is renamed --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9080ad9..b4ebf9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ addons: php: - '7.0' - '7.1' - - '7.2' - - '7.3' - nightly matrix: