Skip to content

Commit 6611f6b

Browse files
author
Mauro Cassani
committed
Docker support
1 parent 28c323f commit 6611f6b

26 files changed

+73
-31
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

Dockerfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
FROM php:7.0-apache
22

3+
# Copy whole project
4+
# Copy parameters.docker.yml into parameters.yml
35
COPY / /var/www/html/
6+
COPY config/parameters.docker.yml /var/www/html/config/parameters.yml
47
WORKDIR /var/www/html/
58

69
# Composer
@@ -18,6 +21,10 @@ RUN apt-get update && apt-get install -y
1821
RUN docker-php-ext-install opcache
1922
RUN pecl install apcu-5.1.5
2023
RUN docker-php-ext-enable apcu
24+
RUN { \
25+
echo 'apc.enabled=1'; \
26+
echo 'apc.enable_cli=1'; \
27+
} >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini
2128

2229
# Install dependencies
23-
RUN composer install --no-interaction
30+
RUN composer install --no-interaction

README.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,11 @@ $console->add(new \InMemoryList\Command\FlushCommand('redis', [
482482

483483
## Testing
484484

485-
In order to run all the test, you need to install **all the drivers** on your machine:
485+
In order to run all the tests, you have two options:
486+
487+
### 1. Install all the drivers on your machine
488+
489+
The first way it to install **all the drivers** on your machine:
486490

487491
* APCU - [(install via PECL)](https://pecl.php.net/package/APCu)
488492
* MEMCACHED - [(install via PECL)](https://pecl.php.net/package/memcached)
@@ -503,6 +507,18 @@ memcached_parameters:
503507
port: '11211'
504508
```
505509
510+
### 2. Run the project with Docker
511+
512+
You can simple run the project with [Docker](https://www.docker.com/):
513+
514+
```
515+
docker-compose build
516+
517+
docker-compose up -d
518+
```
519+
520+
Then, enter in the container and run the tests.
521+
506522
## Built With
507523

508524
* [PRedis](https://github.com/nrk/predis) - Flexible and feature-complete Redis client for PHP and HHVM

tests/bootstrap.php app/bootstrap.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
require __DIR__.'/../vendor/autoload.php';
10+
require __DIR__ . '/../vendor/autoload.php';
1111

1212
use Symfony\Component\Yaml\Exception\ParseException;
1313
use Symfony\Component\Yaml\Yaml;
1414

1515
try {
16-
$config = Yaml::parse(file_get_contents(__DIR__.'/../config/parameters.yml'));
16+
$config = Yaml::parse(file_get_contents(__DIR__ . '/../config/parameters.yml'));
1717

1818
return $config;
1919
} catch (ParseException $e) {

bin/console

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set_time_limit(0);
55

66
require __DIR__.'/../vendor/autoload.php';
77

8-
$config = require __DIR__.'/../tests/bootstrap.php';
8+
$config = require __DIR__ . '/../app/bootstrap.php';
99

1010
$app = new \Symfony\Component\Console\Application('In Memory List', 'v1.2');
1111

config/parameters.dist.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ redis_parameters:
66
profile: '3.2'
77

88
memcached_parameters:
9-
-
10-
host: 'localhost'
11-
port: '11211'
9+
host: 'localhost'
10+
port: '11211'

config/parameters.docker.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
redis_parameters:
2+
scheme: 'tcp'
3+
host: 'redis'
4+
port: '6379'
5+
options:
6+
profile: '3.2'
7+
8+
memcached_parameters:
9+
host: 'memcached'
10+
port: '11211'

docker-compose.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '2'
2+
3+
services:
4+
app:
5+
build: .
6+
links:
7+
- redis:redis
8+
- memcached:memcached
9+
ports:
10+
- "5000:80"
11+
12+
redis:
13+
image: redis
14+
restart: always
15+
16+
memcached:
17+
image: memcached
18+
restart: always

examples/apcu/albums.php

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../shared.php';
13-
1412
$start = microtime(true);
1513
$apiUrl = 'https://jsonplaceholder.typicode.com/albums';
1614
$apiArray = json_decode(file_get_contents($apiUrl));

examples/apcu/benchmark.php

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../shared.php';
13-
1412
$start = microtime(true);
1513

1614
$from = (isset($_GET['from'])) ?: 1;

examples/apcu/comments.php

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../shared.php';
13-
1412
$start = microtime(true);
1513
$apiUrl = 'https://jsonplaceholder.typicode.com/comments';
1614
$apiArray = json_decode(file_get_contents($apiUrl));

examples/apcu/photos.php

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../shared.php';
13-
1412
$start = microtime(true);
1513
$apiUrl = 'https://jsonplaceholder.typicode.com/photos';
1614
$apiArray = json_decode(file_get_contents($apiUrl));

examples/memcached/albums.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515
$apiUrl = 'https://jsonplaceholder.typicode.com/albums';

examples/memcached/benchmark.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515

examples/memcached/comments.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515
$apiUrl = 'https://jsonplaceholder.typicode.com/comments';

examples/memcached/photos.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515
$apiUrl = 'https://jsonplaceholder.typicode.com/photos';

examples/redis/albums.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515
$apiUrl = 'https://jsonplaceholder.typicode.com/albums';

examples/redis/benchmark.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515

examples/redis/comments.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515
$apiUrl = 'https://jsonplaceholder.typicode.com/comments';

examples/redis/photos.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../../tests/bootstrap.php';
12+
include __DIR__ . '/../../app/bootstrap.php';
1313

1414
$start = microtime(true);
1515
$apiUrl = 'https://jsonplaceholder.typicode.com/photos';

examples/simple-array-with-headers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../tests/bootstrap.php';
12+
include __DIR__ . '/../app/bootstrap.php';
1313

1414
$simpleArray = json_encode([
1515
[

examples/simple-array.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
use InMemoryList\Application\Client;
1111

12-
include __DIR__.'/../tests/bootstrap.php';
12+
include __DIR__ . '/../app/bootstrap.php';
1313

1414
$simpleArray = json_encode([
1515
[

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
~ file that was distributed with this source code.
1010
-->
1111

12-
<phpunit bootstrap="tests/bootstrap.php"
12+
<phpunit bootstrap="app/bootstrap.php"
1313
colors="true"
1414
convertErrorsToExceptions="true"
1515
convertNoticesToExceptions="true"

tests/BaseTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BaseTestCase extends TestCase
2929
*/
3030
public function setUp()
3131
{
32-
$config = require __DIR__.'/../tests/bootstrap.php';
32+
$config = require __DIR__ . '/../app/bootstrap.php';
3333
$this->memcached_parameters = $config['memcached_parameters'];
3434
$this->redis_parameters = $config['redis_parameters'];
3535
}

tests/Command/FlushCommandTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function it_displays_correctly_redis_flush_message()
7171
$output = $commandTester->getDisplay();
7272

7373
$this->assertEquals('redis', $command->getDriver());
74-
$this->assertEquals('127.0.0.1', $command->getParameters()['host']);
75-
$this->assertEquals(6379, $command->getParameters()['port']);
74+
$this->assertEquals($this->redis_parameters['host'], $command->getParameters()['host']);
75+
$this->assertEquals($this->redis_parameters['port'], $command->getParameters()['port']);
7676
$this->assertContains('[redis] Cache was successful flushed.', $output);
7777
}
7878
}

tests/InMemoryList/Infrastructure/Drivers/RedisDriverTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function setUp()
2020
/**
2121
* @test
2222
* @expectedException \Predis\Connection\ConnectionException
23-
* @expectedExceptionMessage `AUTH` failed: ERR Client sent AUTH, but no password is set [tcp://127.0.0.1:6379]
2423
*/
2524
public function it_throws_ConnectionException_if_wrong_config_array_is_provided()
2625
{

0 commit comments

Comments
 (0)