Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration Testing #132

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TESTING=1
DEBUG=1
EXCHANGE=bl3p
BL3P_PRIVATE_KEY=foo
BL3P_PUBLIC_KEY=bar
NOTIFICATION_EMAIL_ENABLED=false
NOTIFICATION_TELEGRAM_ENABLED=false
BASE_CURRENCY=EUR
DISABLE_VERSION_CHECK=off
WITHDRAW_ADDRESS=bc1qnz3d3dy27tgwsfazmf933n9gdk00r3m2pyrhzf
14 changes: 10 additions & 4 deletions .github/workflows/run-tests-on-change.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build the Docker image and execute the testsuite
- name: Build the Docker development image
uses: docker/build-push-action@v2
with:
context: .
push: false
target: testing_stage
target: development_build
load: true
tags: jorijn/bitcoin-dca:ci
cache-from: type=registry,ref=jorijn/bitcoin-dca:latest

- name: Extract the test logging artifacts from the container that was built
- name: Install the development dependencies
run: docker run --rm --entrypoint= -v ${GITHUB_WORKSPACE}:/app/ jorijn/bitcoin-dca:ci composer install --no-interaction --no-plugins --no-scripts --prefer-dist --no-ansi --ignore-platform-reqs

- name: Run the PHPUnit tests
run: |
docker run --rm --entrypoint= -v ${GITHUB_WORKSPACE}:/app/ jorijn/bitcoin-dca:ci sh -c "cp /tmp/tests_*.xml /app/"
docker run --rm --entrypoint= -v ${GITHUB_WORKSPACE}:/app/ jorijn/bitcoin-dca:ci vendor/bin/phpunit --testdox --coverage-clover /app/tests_coverage.xml --log-junit /app/tests_log.xml
sed -i "s/\/app\//\/github\/workspace\//g" tests_coverage.xml tests_log.xml

- name: Run the Behat integration tests
run: docker run --rm --entrypoint= -v ${GITHUB_WORKSPACE}:/app/ jorijn/bitcoin-dca:ci vendor/bin/behat -f pretty

- name: Upload logging artifacts
uses: actions/upload-artifact@v2
with:
Expand Down
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@ RUN apk --no-cache update \
&& pecl install pcov xdebug \
&& docker-php-ext-enable pcov xdebug

##################################################################################################################
# Test Stage
##################################################################################################################
FROM development_build AS testing_stage

# run the test script(s) from composer, this validates the application before allowing the build to succeed
# this does make the tests run multiple times, but with different architectures
RUN composer install --no-interaction --no-plugins --no-scripts --prefer-dist --no-ansi --ignore-platform-reqs
RUN vendor/bin/phpunit --testdox --coverage-clover /tmp/tests_coverage.xml --log-junit /tmp/tests_log.xml
WORKDIR /app/

##################################################################################################################
# Production Stage
Expand All @@ -74,5 +66,7 @@ FROM base_image as production_build

COPY docker/php-production.ini "$PHP_INI_DIR/php.ini"

WORKDIR /app/

# run the app to precompile the DI container
RUN /app/bin/bitcoin-dca
17 changes: 17 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
default:
formatters:
pretty: true
suites:
domain_features:
services: Jorijn\Bitcoin\Dca\Factory\ContainerFactory::createContainer
paths:
- '%paths.base%/features'
contexts:
- Features\Jorijn\Bitcoin\Dca\ApplicationContext: ~
- Features\Jorijn\Bitcoin\Dca\BuyingContext:
- '@service.buy.mockexchange'
- Features\Jorijn\Bitcoin\Dca\WithdrawingContext:
- '@service.withdraw.mockexchange'
- Features\Jorijn\Bitcoin\Dca\TaggingContext:
- '@application'
- '@repository.tag_integer.balance'
59 changes: 5 additions & 54 deletions bin/bitcoin-dca
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
#!/usr/bin/env php
<?php

require_once __DIR__.'/../vendor/autoload.php';
declare(strict_types=1);

use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';

if (file_exists(__DIR__.'/../.env')) {
$dotenv = new Dotenv();
$dotenv->loadEnv(__DIR__.'/../.env');
}
use Jorijn\Bitcoin\Dca\Factory\ContainerFactory;

set_error_handler(
static function ($errno, $errstr, $errfile, $errline) {
Expand All @@ -28,43 +17,5 @@ set_error_handler(
}
);

$containerCache = __DIR__.'/../var/cache/container.php';
$containerConfigCache = new ConfigCache($containerCache, $_SERVER['DEBUG'] ?? false);

if (!$containerConfigCache->isFresh()) {
$containerBuilder = new ContainerBuilder();

// load the DI config
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__.'/../config/'));
$loader->load('services.yaml');

$containerBuilder->addCompilerPass(new AddConsoleCommandPass());
$containerBuilder->addCompilerPass(new RegisterListenersPass());
$containerBuilder->addCompilerPass(new SerializerPass());
$containerBuilder->setParameter('application.path', dirname(__DIR__));

$versionFile = dirname(__DIR__).DIRECTORY_SEPARATOR.'version.json';
if (file_exists($versionFile)) {
$version = json_decode(file_get_contents($versionFile), true, 512, JSON_THROW_ON_ERROR);
if (isset($version['version'])) {
$containerBuilder->setParameter('application_version', $version['version']);
}
}

$containerBuilder->compile();

// write the compiled container to file
$dumper = new PhpDumper($containerBuilder);
$containerConfigCache->write(
$dumper->dump(['class' => 'BitcoinDcaContainer']),
$containerBuilder->getResources()
);
}

require_once $containerCache;
$container = new BitcoinDcaContainer();

$application = $container->get('application');
$application->setCommandLoader($container->get('console.command_loader'));
$application->setDispatcher($container->get('event_dispatcher'));
$application->run();
$container = ContainerFactory::createContainer();
$container->get('application')->run();
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\Jorijn\\Bitcoin\\Dca\\": "tests/"
"Tests\\Jorijn\\Bitcoin\\Dca\\": "tests/",
"Features\\Jorijn\\Bitcoin\\Dca\\": "features/bootstrap/"
}
},
"scripts": {
"test": "vendor/bin/phpunit --testdox",
"php-cs-fixer": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix"
"php-cs-fixer": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix",
"behat": "vendor/bin/behat"
},
"require-dev": {
"phpunit/phpunit": "^9.1",
"rector/rector": "^0.12.5"
"rector/rector": "^0.12.5",
"behat/behat": "^3.10"
}
}
Loading