Skip to content

Commit 3bd4128

Browse files
committed
Reorganize tests.
Drop test bootstrap in favor of using the phpunit script from composer which does the autoloading for us. Updating test requirements in README. Flattening hirachy in tests directory. Renaming bench file. Use env vars for specifiying the test server location.
1 parent 1c69f27 commit 3bd4128

7 files changed

+39
-56
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
vendor

README

+11-3
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,20 @@ Running the Tests
9797
The integration tests contained in this library require a running beanstalkd
9898
instance. You'll need to start a dedicated instance on port 11301 as follows.
9999

100-
$ beanstalkd -VV -l 127.0.0.1 -p 11301
100+
```
101+
beanstalkd -VV -l 127.0.0.1 -p 11301
102+
```
101103

102104
Tests for this library are PHPUnit based. To run the tests you'll need
103105
to have PHPUnit installed[1]. Following commands will run all the tests.
104106

105-
$ cd /path/to/beanstalk
106-
$ phpunit
107+
```
108+
cd /path/to/beanstalk
109+
composer install
110+
111+
export TEST_BEANSTALKD_HOST=127.0.0.1
112+
export TEST_BEANSTALKD_PORT=11301
113+
vendor/bin/phpunit tests
114+
```
107115

108116
[1] http://www.phpunit.de/manual/current/en/installation.html

phpunit.xml

-24
This file was deleted.

tests/integration/ConnectTest.php tests/ConnectTest.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ class ConnectTest extends \PHPUnit_Framework_TestCase {
1717
public $subject;
1818

1919
protected function setUp() {
20-
$this->subject = new Client([
21-
'host' => TEST_SERVER_HOST,
22-
'port' => TEST_SERVER_PORT
23-
]);
20+
$host = getenv('TEST_BEANSTALKD_HOST');
21+
$port = getenv('TEST_BEANSTALKD_PORT');
22+
23+
if (!$host || !$port) {
24+
$message = 'TEST_BEANSTALKD_HOST and/or TEST_BEANSTALKD_PORT env variables not defined.';
25+
$this->markTestSkipped($message);
26+
}
27+
$this->subject = new Client(compact('host', 'port'));
28+
2429
if (!$this->subject->connect()) {
25-
$message = 'Need a running beanstalk server at ' . TEST_SERVER_HOST . ':' . TEST_SERVER_PORT;
30+
$message = "Need a running beanstalkd server at {$host}:{$port}.";
2631
$this->markTestSkipped($message);
2732
}
2833
}

tests/integration/ProducerTest.php tests/ProducerTest.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ class ProducerTest extends \PHPUnit_Framework_TestCase {
1717
public $subject;
1818

1919
protected function setUp() {
20-
$this->subject = new Client([
21-
'host' => TEST_SERVER_HOST,
22-
'port' => TEST_SERVER_PORT
23-
]);
20+
$host = getenv('TEST_BEANSTALKD_HOST');
21+
$port = getenv('TEST_BEANSTALKD_PORT');
22+
23+
if (!$host || !$port) {
24+
$message = 'TEST_BEANSTALKD_HOST and/or TEST_BEANSTALKD_PORT env variables not defined.';
25+
$this->markTestSkipped($message);
26+
}
27+
$this->subject = new Client(compact('host', 'port'));
28+
2429
if (!$this->subject->connect()) {
25-
$message = 'Need a running beanstalk server at ' . TEST_SERVER_HOST . ':' . TEST_SERVER_PORT;
30+
$message = "Need a running beanstalkd server at {$host}:{$port}.";
2631
$this->markTestSkipped($message);
2732
}
33+
2834
foreach ($this->subject->listTubes() as $tube) {
2935
$this->subject->useTube($tube);
3036

tests/bench.php tests/PutBench.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
* Redistributions of files must retain the above copyright notice.
99
*/
1010

11-
namespace Beanstalk\Tests;
11+
namespace Beanstalk;
1212

1313
use Beanstalk\Client;
1414

1515
/**
1616
* A small benchmark to test throughput.
1717
*/
18-
$connection = new Client();
18+
$connection = new Client([
19+
'host' => getenv('TEST_BEANSTALKD_HOST'),
20+
'port' => getenv('TEST_BEANSTALKD_PORT')
21+
]);
1922
for ($i = 0; $i < 100000; $i++) {
2023
$connection->put(1024, 0, 60, $i);
2124
}

tests/bootstrap.php

-17
This file was deleted.

0 commit comments

Comments
 (0)