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

PHPunit speed up attempt #193

Merged
merged 2 commits into from
Sep 21, 2020
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: make env=ci cs-check;make env=ci phpstan;make env=ci layer;make env=ci psalm

- name: Tests
run: make env=ci xon;make env=ci conf="--coverage-clover build/logs/clover.xml" phpunit
run: make env=ci xoff;make env=ci conf="--coverage-clover build/logs/clover.xml" phpunit

- name: ARTIFACT
run: make env=ci artifact
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
###> symfony/framework-bundle ###
.env
.env.blackfire
/public/bundles/
/var/
/vendor/
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"symfony/yaml": "^5.1"
},
"require-dev": {
"blackfire/php-sdk": "^1.23",
"dama/doctrine-test-bundle": "^6.3",
"phpstan/phpstan": "^0.12.42",
"phpunit/phpunit": "v9.3",
Expand Down
149 changes: 143 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/packages/test/security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
security:
encoders:
bcrypt:
algorithm: bcrypt
cost: 4
20 changes: 16 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ services:
- php

code:
image: jorge07/alpine-php:7.4.3-dev
build:
dockerfile: etc/artifact/Dockerfile
context: .
target: php-dev
volumes:
- ./:/app:rw,delegated
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
Expand All @@ -21,7 +24,10 @@ services:
- /app/var/sessions/

php:
image: jorge07/alpine-php:7.4.3-dev
build:
dockerfile: etc/artifact/Dockerfile
context: .
target: php-dev
volumes:
- ./:/app:rw,delegated
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
Expand All @@ -35,7 +41,10 @@ services:
- elasticsearch

workers_events:
image: jorge07/alpine-php:7.4.3-dev
build:
dockerfile: etc/artifact/Dockerfile
context: .
target: php-dev
volumes:
- ./:/app:rw,delegated
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
Expand All @@ -49,7 +58,10 @@ services:
- rmq
- elasticsearch
workers_users:
image: jorge07/alpine-php:7.4.3-dev
build:
dockerfile: etc/artifact/Dockerfile
context: .
target: php-dev
volumes:
- ./:/app:rw,delegated
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
Expand Down
23 changes: 23 additions & 0 deletions etc/artifact/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
ARG PHP_VERION=7.4.3

FROM jorge07/alpine-php:${PHP_VERION}-dev as php-dev

ENV PHP_INI_DIR /etc/php7

RUN apk add -U sqlite \
&& version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz \
&& mkdir -p /tmp/blackfire \
&& curl -A "Docker" -L https://blackfire.io/api/v1/releases/client/linux_static/amd64 | tar zxp -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire /usr/bin/blackfire \
&& rm -Rf /tmp/blackfire \
&& apk add --no-cache php-dev g++ autoconf make pcre2-dev \
&& pecl install pcov \
&& apk del --no-cache php-dev g++ autoconf make pcre2-dev \
&& echo "extension=pcov.so" >> /etc/php7/php.ini \
&& echo "pcov.enabled=0" >> /etc/php7/php.ini

FROM jorge07/alpine-php:${PHP_VERION}-dev as builder

WORKDIR /app
Expand Down
7 changes: 7 additions & 0 deletions etc/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ services:
environment:
PHP_IDE_CONFIG: serverName=es.local

blackfire:
image: blackfire/blackfire
env_file:
- .env.blackfire
environment:
BLACKFIRE_LOG_LEVEL: 4

mysql:
ports:
- "3306:3306"
Expand Down
7 changes: 4 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rebuild: start ## same as start

.PHONY: erase
erase: ## stop and delete containers, clean volumes.
touch .env.blackfire
$(compose) stop
docker-compose rm -v -f

Expand Down Expand Up @@ -56,7 +57,7 @@ up: ## spin up environment

.PHONY: phpunit
phpunit: db ## execute project unit tests
$(compose) exec -T php sh -lc "./vendor/bin/phpunit $(conf)"
$(compose) exec -T php sh -lc "php -dpcov.enabled='1' -dpcov.directory=. -dpcov.exclude='~vendor~' ./vendor/bin/phpunit $(conf)"

.PHONY: coverage
coverage:
Expand Down Expand Up @@ -98,11 +99,11 @@ schema-validate: ## validate database schema

.PHONY: xon
xon: ## activate xdebug simlink
$(compose) exec -T php sh -lc 'xon'
$(compose) exec -T php sh -lc 'xon | true'

.PHONY: xoff
xoff: ## deactivate xdebug
$(compose) exec -T php sh -lc 'xoff'
$(compose) exec -T php sh -lc 'xoff | true'

.PHONY: sh
sh: ## gets inside a container, use 's' variable to select a service. make s=php sh
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</testsuites>
<logging/>
<listeners>
<listener class="App\Tests\TidierListener"/>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
<listener class="\DAMA\DoctrineTestBundle\PHPUnit\PHPUnitListener"/>
</listeners>
Expand Down
13 changes: 13 additions & 0 deletions src/Domain/User/ValueObject/Auth/HashedPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static function fromHash(string $hashedPassword): self

public function match(string $plainPassword): bool
{
if (self::isTestSuite()) {
return $this->hashedPassword === $plainPassword;
}

return \password_verify($plainPassword, $this->hashedPassword);
}

Expand All @@ -45,6 +49,10 @@ private static function hash(string $plainPassword): string
{
Assertion::minLength($plainPassword, 6, 'Min 6 characters password');

if (self::isTestSuite()) {
return $plainPassword;
}

Comment on lines +52 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 👍🏼 . ( Link doesn't work 😞 )

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2020-09-21 at 13 19 43

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10+5s just encrypting and decrypting

/** @var string|bool|null $hashedPassword */
$hashedPassword = \password_hash($plainPassword, PASSWORD_BCRYPT, ['cost' => self::COST]);

Expand All @@ -64,4 +72,9 @@ public function __toString(): string
{
return $this->hashedPassword;
}

private static function isTestSuite(): bool
{
return \getenv('APP_ENV') === 'test';
}
}
1 change: 1 addition & 0 deletions tests/Application/ApplicationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected function fireTerminateEvent(): void

protected function tearDown(): void
{
parent::tearDown();
$this->commandBus = null;
$this->queryBus = null;
}
Expand Down
Loading