Skip to content

Commit

Permalink
build(makefile) clean up for CI, optimize build order
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Feb 27, 2023
1 parent 1e4f145 commit 009d55a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phpcs
run: make code_sniff
run: make phpcs
phpstan:
name: phpstan on PHP 5.6
runs-on: ubuntu-latest
Expand All @@ -27,7 +27,7 @@ jobs:
php-version: 5.6
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phpcs
- name: Run phpstan
run: make phpstan
phan:
name: phan on PHP 5.6
Expand Down
6 changes: 6 additions & 0 deletions bin/create-app-facade
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ $appFacadeContentsTemplate = <<< PHP_CODE
namespace lucatume\DI52;
use lucatume\DI52\Builders\ValueBuilder;
/**
* Class App
*
Expand Down Expand Up @@ -117,6 +119,10 @@ foreach ($containerPublicMethods as $method) {
', ',
array_map(
static function (ReflectionParameter $p) {
if($p->isVariadic()){
return '...$' . $p->getName();
}

return '$' . $p->getName();
},
$method->getParameters()
Expand Down
31 changes: 20 additions & 11 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ build: $(build_php_versions) ## Builds the project PHP images.
mkdir -p var/cache/composer
mkdir -p var/log
# Foreach PHP version build a Docker image.
$(foreach version,$(php_versions), \
for version in $(php_versions); do \
docker build \
--build-arg PHP_VERSION=$(version) \
--build-arg PHP_VERSION=$${version} \
--build-arg XDEBUG_REMOTE_HOST=$${XDEBUG_REMOTE_HOST:-host.docker.internal} \
--build-arg XDEBUG_REMOTE_PORT=$${XDEBUG_REMOTE_PORT:-9009} \
--build-arg WORKDIR=${PWD} \
config/containers/php \
--tag lucatume/di52-dev:php-v$(version); \
)
--tag lucatume/di52-dev:php-v$${version}; \
done
.PHONY: build

lint: ## Lint the project source files to make sure they are PHP 5.6 compatible.
Expand Down Expand Up @@ -54,7 +54,6 @@ phpcbf: ## Run PHP Code Sniffer Beautifier on the project source files.

PHPSTAN_LEVEL?=max
phpstan: ## Run phpstan on the project source files, PHP 5.6 version.
PHP_VERSION=5.6 $(MAKE) composer_update
docker run --rm \
-v ${PWD}:${PWD} \
-u "$$(id -u):$$(id -g)" \
Expand All @@ -64,7 +63,6 @@ phpstan: ## Run phpstan on the project source files, PHP 5.6 version.
.PHONY: phpstan

phan: ## Run phan on the project source files, PHP 5.6 version.
PHP_VERSION=5.6 $(MAKE) composer_update
docker run --rm \
-v ${PWD}:/mnt/src \
-u "$$(id -u):$$(id -g)" \
Expand All @@ -80,6 +78,15 @@ composer_update:
lucatume/di52-dev:php-v${PHP_VERSION} update -W
.PHONY: composer_update

composer_update_56:
docker run --rm \
-e COMPOSER_CACHE_DIR=${PWD}/var/cache/composer \
-v "${PWD}:${PWD}" \
-w ${PWD} \
--entrypoint composer \
lucatume/di52-dev:php-v5.6 update -W
.PHONY: composer_update_56

test_run: ## Run the test on the specified PHP version with XDebug support. Example `PHP_VERSION=7.2 make test_run`.
docker run --rm \
-e COMPOSER_CACHE_DIR="${PWD}/var/cache/composer" \
Expand All @@ -88,14 +95,14 @@ test_run: ## Run the test on the specified PHP version with XDebug support. Exam
"lucatume/di52-dev:php-v${PHP_VERSION}" run_tests --no-coverage
.PHONY: test_run

test: lint phpcbf phpcs phpstan phan ## Runs the project PHPUnit tests on all PHP versions.
$(foreach version,$(php_versions), \
test: composer_update_56 lint phpcs phpstan phan ## Runs the project PHPUnit tests on all PHP versions.
for version in $(php_versions); do \
docker run --rm \
-e COMPOSER_CACHE_DIR="${PWD}/var/cache/composer" \
-v "${PWD}:${PWD}" \
-w "${PWD}" \
"lucatume/di52-dev:php-v$(version)" run_tests --no-coverage; \
)
lucatume/di52-dev:php-v$${version} run_tests --no-coverage || exit 1; \
done
.PHONY: test

clean:
Expand Down Expand Up @@ -130,5 +137,7 @@ app_facade: ## Creates or updates the src/App.php file from the current Containe
-v "${PWD}:${PWD}" \
-w "${PWD}" \
lucatume/di52-dev:php-v8.0 php bin/create-app-facade;
$(MAKE) phpcbf
$(MAKE) phpstan
$(MAKE) phpcbf || exit 0
$(MAKE) phpcs
.PHONY: app_facade
8 changes: 5 additions & 3 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace lucatume\DI52;

use lucatume\DI52\Builders\ValueBuilder;

/**
* Class App
*
Expand Down Expand Up @@ -282,7 +284,7 @@ public static function hasTag($tag)
*/
public static function register($serviceProviderClass, ...$alias)
{
static::container()->register($serviceProviderClass, $alias);
static::container()->register($serviceProviderClass, ...$alias);
}

/**
Expand Down Expand Up @@ -523,10 +525,10 @@ public static function isBound($id)
*
* @param int $maskThrowables The mask for the throwables that should be caught and re-thrown as container
*
* @return $this This instance.
* @return void
*/
public static function setExceptionMask($maskThrowables)
{
return static::container()->setExceptionMask($maskThrowables);
static::container()->setExceptionMask($maskThrowables);
}
}
4 changes: 1 addition & 3 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -863,12 +863,10 @@ public function isBound($id)
*
* @param int $maskThrowables The mask for the throwables that should be caught and re-thrown as container
*
* @return $this This instance.
* @return void
*/
public function setExceptionMask($maskThrowables)
{
$this->maskThrowables = (int)$maskThrowables;

return $this;
}
}
12 changes: 6 additions & 6 deletions tests/unit/ThrowableTraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function test_exception_casting(
$this->expectException($expectedExceptionClass);

try {
$container = (new Container())
->setExceptionMask($maskThrowables);
$container = new Container();
$container->setExceptionMask($maskThrowables);
$container->get(ThrowExceptionOnConstructClass::class);
} catch (Exception $e) {
assertMatchesSnapshots(dumpThrowable($e));
Expand Down Expand Up @@ -104,8 +104,8 @@ public function test_error_casting(
$this->expectException($expectedExceptionClass);

try {
$container = (new Container())
->setExceptionMask($maskThrowables);
$container = new Container();
$container->setExceptionMask($maskThrowables);
$container->get(ThrowErrorOnConstructClass::class);
} catch (Exception $e) {
assertMatchesSnapshots(dumpThrowable($e));
Expand Down Expand Up @@ -157,8 +157,8 @@ public function test_parse_error_casting(
$this->expectException($expectedExceptionClass);

try {
$container = (new Container())
->setExceptionMask($maskThrowables);
$container = new Container();
$container->setExceptionMask($maskThrowables);
$container->get(ThrowParseErrorOnConstructClass::class);
} catch (Exception $e) {
assertMatchesSnapshots(dumpThrowable($e));
Expand Down

0 comments on commit 009d55a

Please sign in to comment.