Skip to content

Commit 333a6e5

Browse files
committed
Move tests from Simpletest to PHPUnit and Mockery.
1 parent bcf587f commit 333a6e5

File tree

126 files changed

+6309
-5490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+6309
-5490
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ php:
99
before_script:
1010
- cp tests/acceptance.conf.php.default tests/acceptance.conf.php
1111
- cp tests/smoke.conf.php.default tests/smoke.conf.php
12+
- composer self-update
13+
- composer update --no-interaction --prefer-source
1214
- gem install mailcatcher
1315
- mailcatcher --smtp-port 4456
1416

1517
script:
16-
- php test-suite/run.php
18+
- phpunit
1719

1820
matrix:
1921
allow_failures:

build.xml

+1-20
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,12 @@
2323
<property name="src.readmefile" value="${path}/README" />
2424
<property name="src.changesfile" value="${path}/CHANGES" />
2525
<property name="src.libdir" value="${path}/lib" />
26-
<property name="src.testsuite" value="${path}/test-suite" />
2726
<property name="src.tests" value="${path}/tests" />
2827
<property name="builddir.package" value="${builddir}/${bundle.name}" />
2928
<property name="runtests" value="" />
3029
<filelist id="src.licenses" dir="${path}">
3130
<file name="LICENSE" />
3231
</filelist>
33-
<fileset id="build.simpletest.unneeded"
34-
dir="${builddir.package}/test-suite/lib/simpletest">
35-
<include name="docs/" />
36-
<include name="tutorials/" />
37-
<include name="extensions/" />
38-
<include name="test/" />
39-
<include name="packages/" />
40-
</fileset>
4132

4233

4334
<!-- Bundle all files into a central location -->
@@ -79,15 +70,9 @@
7970
</replacetokens>
8071
</filterchain>
8172
</copy>
82-
<copy todir="${builddir.package}/test-suite">
83-
<fileset dir="${src.testsuite}" />
84-
</copy>
8573
<copy todir="${builddir.package}/tests">
8674
<fileset dir="${src.tests}" />
8775
</copy>
88-
<delete includeemptydirs="true">
89-
<fileset refid="build.simpletest.unneeded" />
90-
</delete>
9176
</target>
9277

9378
<!-- Package up the project as a gzip file -->
@@ -102,11 +87,7 @@
10287

10388
<!-- Run the included unit tests -->
10489
<target name="test" depends="prepare, clean, copy-classes">
105-
<exec executable="php" failonerror="true">
106-
<env key="_" value="php" />
107-
<arg value="${builddir.package}/test-suite/run.php" />
108-
<arg value="${runtests}" />
109-
</exec>
90+
<exec executable="phpunit" failonerror="true" />
11091
</target>
11192

11293
</project>

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"require": {
1818
"php": ">=5.2.4"
1919
},
20+
"require-dev": {
21+
"mockery/mockery": "~0.9@dev"
22+
},
2023
"autoload": {
2124
"files": ["lib/swift_required.php"]
2225
},

phpunit.xml.dist

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
bootstrap="tests/bootstrap.php"
12+
>
13+
<php>
14+
<ini name="intl.default_locale" value="en"/>
15+
<ini name="intl.error_level" value="0"/>
16+
<ini name="memory_limit" value="-1"/>
17+
</php>
18+
19+
<testsuites>
20+
<testsuite name="SwiftMailer unit tests">
21+
<directory>tests/unit</directory>
22+
</testsuite>
23+
<testsuite name="SwiftMailer acceptance tests">
24+
<directory>tests/acceptance</directory>
25+
</testsuite>
26+
<testsuite name="SwiftMailer bug">
27+
<directory>tests/bug</directory>
28+
</testsuite>
29+
<testsuite name="SwiftMailer smoke tests">
30+
<directory>tests/smoke</directory>
31+
</testsuite>
32+
</testsuites>
33+
34+
<listeners>
35+
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
36+
</listeners>
37+
</phpunit>

tests/IdenticalBinaryConstraint.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/**
4+
* A binary safe string comparison.
5+
* @package Swift
6+
* @subpackage Tests
7+
* @author Chris Corbyn
8+
*/
9+
class IdenticalBinaryConstraint extends \PHPUnit_Framework_Constraint
10+
{
11+
protected $value;
12+
13+
public function __construct($value)
14+
{
15+
$this->value = $value;
16+
}
17+
18+
/**
19+
* Evaluates the constraint for parameter $other. Returns TRUE if the
20+
* constraint is met, FALSE otherwise.
21+
*
22+
* @param mixed $other Value or object to evaluate.
23+
* @return bool
24+
*/
25+
public function matches($other)
26+
{
27+
$aHex = $this->asHexString($this->value);
28+
$bHex = $this->asHexString($other);
29+
30+
return $aHex === $bHex;
31+
}
32+
33+
/**
34+
* Returns a string representation of the constraint.
35+
*
36+
* @return string
37+
*/
38+
public function toString()
39+
{
40+
return 'indentical binary';
41+
}
42+
43+
/**
44+
* Get the given string of bytes as a stirng of Hexadecimal sequences.
45+
*
46+
* @param string $binary
47+
*
48+
* @return string
49+
*/
50+
private function asHexString($binary)
51+
{
52+
$hex = '';
53+
54+
$bytes = unpack('H*', $binary);
55+
56+
foreach ($bytes as &$byte) {
57+
$byte = strtoupper($byte);
58+
}
59+
60+
return implode('', $bytes);
61+
}
62+
}

tests/StreamCollector.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
class Swift_StreamCollector
4+
{
5+
public $content = '';
6+
7+
public function __invoke($arg)
8+
{
9+
$this->content .= $arg;
10+
}
11+
}

tests/helpers/Swift/Tests/SwiftSmokeTestCase.php renamed to tests/SwiftMailerSmokeTestCase.php

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?php
22

3-
require_once 'Swift/Tests/SwiftUnitTestCase.php';
4-
require_once 'swift_required.php';
5-
63
/**
7-
* Smoke test helper class.
8-
* @package Swift
9-
* @subpackage Tests
10-
* @author Chris Corbyn
4+
* Base test for smoke tests.
5+
*
6+
* @package Swift
7+
* @subpackage Tests
8+
* @author Rouven Weßling
119
*/
12-
class Swift_Tests_SwiftSmokeTestCase extends Swift_Tests_SwiftUnitTestCase
10+
class SwiftMailerSmokeTestCase extends SwiftMailerTestCase
1311
{
14-
public function skip()
12+
public function setUp()
1513
{
16-
$this->skipUnless(SWIFT_SMOKE_TRANSPORT_TYPE,
17-
'%s: Smoke tests are skipped if tests/smoke.conf.php is not edited'
18-
);
14+
if (!defined('SWIFT_SMOKE_TRANSPORT_TYPE')) {
15+
$this->markTestSkipped(
16+
'Smoke tests are skipped if tests/smoke.conf.php is not edited'
17+
);
18+
}
1919
}
2020

2121
protected function _getMailer()
@@ -45,9 +45,4 @@ protected function _getMailer()
4545

4646
return new Swift_Mailer($transport);
4747
}
48-
49-
protected function _visualCheck($url)
50-
{
51-
$this->dump('{image @ ' . $url . '}');
52-
}
5348
}

tests/SwiftMailerTestCase.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* A base test case with some custom expectations.
5+
* @package Swift
6+
* @subpackage Tests
7+
* @author Rouven Weßling
8+
*/
9+
class SwiftMailerTestCase extends \PHPUnit_Framework_TestCase
10+
{
11+
public static function regExp($pattern)
12+
{
13+
if (!is_string($pattern)) {
14+
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
15+
}
16+
17+
return new PHPUnit_Framework_Constraint_PCREMatch($pattern);
18+
}
19+
20+
public function assertIdenticalBinary($expected, $actual, $message = '')
21+
{
22+
$constraint = new IdenticalBinaryConstraint($expected);
23+
self::assertThat($actual, $constraint, $message);
24+
}
25+
26+
protected function tearDown()
27+
{
28+
\Mockery::close();
29+
}
30+
31+
protected function getMockery($class)
32+
{
33+
return \Mockery::mock($class);
34+
}
35+
}

tests/acceptance/Swift/AttachmentAcceptanceTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php
22

33
require_once 'swift_required.php';
4-
require_once 'Swift/Mime/AttachmentAcceptanceTest.php';
4+
require_once __DIR__ . '/Mime/AttachmentAcceptanceTest.php';
55

6-
class Swift_AttachmentAcceptanceTest
7-
extends Swift_Mime_AttachmentAcceptanceTest
6+
class Swift_AttachmentAcceptanceTest extends Swift_Mime_AttachmentAcceptanceTest
87
{
98
protected function _createAttachment()
109
{

0 commit comments

Comments
 (0)