Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Actually run tests on different PHP versions #141

Merged
merged 12 commits into from
Mar 29, 2023
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
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PHP_VERSION=7.4
20 changes: 12 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: yii2-openapi
on:
push:
branches: [ master, wip]
branches: [ master ]
pull_request:
branches: [ master, wip ]
branches: [ master ]
paths-ignore:
- 'docs/**'
- '*.md'
Expand All @@ -18,13 +18,16 @@ jobs:
DB_PASSWORD: dbpass
DB_CHARSET: utf8
strategy:
fail-fast: true
fail-fast: false
matrix:
php-versions: ['7.1', '7.2', '7.3', '7.4']
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

# TODO use cache
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set PHP Version
run: echo "PHP_VERSION=${{ matrix.php-versions }}" > .env

# Run every tests inside Docker container
- name: Docker Compose Setup
Expand All @@ -40,13 +43,14 @@ jobs:
run: make up

- name: Install Docker and composer dependencies
run: make installdocker
run: docker-compose exec php php -v && make installdocker

- name: Migrate
run: make migrate
run: make UID=0 migrate

- name: Check style
if: "!contains(matrix.php-versions, '8.')"
run: make check-style-from-host

- name: Run tests
run: make testdocker
run: make UID=0 testdocker
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/composer.lock
/phpunit.xml
/.php_cs.cache
/.env
/.phpunit.result.cache
88 changes: 88 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Yii2-openapi Contribution Docs
==============================

To contribute or play around, steps to set up this project up locally are:

```bash
# in your CLI
git clone https://github.com/cebe/yii2-openapi.git
cd yii2-openapi
make clean_all
make up
make installdocker
make migrate

# to check everything is setup up correctly ensure all tests passes
make cli
./vendor/bin/phpunit

# create new branch from master and Happy contributing!
```

These commands are available to develop and check the tests. It is available inside the Docker container. To enter into bash shell of container, run `make cli` .

```bash
cd tests
./yii migrate-mysql/up
./yii migrate-mysql/down 4

./yii migrate-maria/up
./yii migrate-maria/down 4

./yii migrate-pgsql/up
./yii migrate-pgsql/down 4
```

To apply multiple migration with one command:

```bash
./yii migrate-mysql/up --interactive=0 && \
./yii migrate-mysql/down --interactive=0 4 && \
./yii migrate-maria/up --interactive=0 && \
./yii migrate-maria/down --interactive=0 4 && \
./yii migrate-pgsql/up --interactive=0 && \
./yii migrate-pgsql/down --interactive=0 4
```


Switching PHP versions
----------------------

You can switch the PHP version of the docker runtime by changing the `PHP_VERSION` environment variable in the `.env` file.

If you have no `.env` file yet, create it by copying `.env.dist` to `.env`.

After changing the PHP Version you need to run `make down up` to start the new container with new version.

Example:

```
$ echo "PHP_VERSION=7.4" > .env
$ make down up cli
Stopping yii2-openapi_php_1 ... done
Stopping yii2-openapi_maria_1 ... done
Stopping yii2-openapi_postgres_1 ... done
Stopping yii2-openapi_mysql_1 ... done
Removing yii2-openapi_php_1 ... done
Removing yii2-openapi_maria_1 ... done
Removing yii2-openapi_postgres_1 ... done
Removing yii2-openapi_mysql_1 ... done
Removing network yii2-openapi_default
Creating network "yii2-openapi_default" with driver "bridge"
Creating yii2-openapi_maria_1 ... done
Creating yii2-openapi_mysql_1 ... done
Creating yii2-openapi_postgres_1 ... done
Creating yii2-openapi_php_1 ... done
docker-compose exec php bash

root@f9928598f841:/app# php -v

PHP 7.4.27 (cli) (built: Jan 26 2022 18:08:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.27, Copyright (c), by Zend Technologies
with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
```



19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PHPARGS=-dmemory_limit=64M
#PHPARGS=-dmemory_limit=64M -dzend_extension=xdebug.so -dxdebug.remote_enable=1 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_autostart=1
#PHPARGS=-dmemory_limit=64M -dxdebug.remote_enable=1

UID=$(shell id -u)

all:

check-style:
Expand Down Expand Up @@ -29,6 +31,9 @@ clean:
sudo rm -rf tests/tmp/app/*
sudo rm -rf tests/tmp/docker_app/*

down:
docker-compose down --remove-orphans

up:
docker-compose up -d
echo "Waiting for mariadb to start up..."
Expand All @@ -39,22 +44,22 @@ up:
docker-compose exec -T mysql timeout 60s sh -c "while ! (mysql --execute \"ALTER USER 'dbuser'@'%' IDENTIFIED WITH mysql_native_password BY 'dbpass';\" > /dev/null 2>&1); do echo -n '.'; sleep 0.1 ; done; echo 'ok'" || (docker-compose ps; docker-compose logs; exit 1)

cli:
docker-compose exec php bash
docker-compose exec --user=$(UID) php bash

migrate:
docker-compose run --rm php sh -c 'mkdir -p "tests/tmp/app"'
docker-compose run --rm php sh -c 'mkdir -p "tests/tmp/docker_app"'
docker-compose run --rm php sh -c 'cd /app/tests && ./yii migrate --interactive=0'
docker-compose run --user=$(UID) --rm php sh -c 'mkdir -p "tests/tmp/app"'
docker-compose run --user=$(UID) --rm php sh -c 'mkdir -p "tests/tmp/docker_app"'
docker-compose run --user=$(UID) --rm php sh -c 'cd /app/tests && ./yii migrate --interactive=0'

installdocker:
docker-compose run --rm php composer install && chmod +x tests/yii
docker-compose run --user=$(UID) --rm php composer install && chmod +x tests/yii

testdocker:
docker-compose run --rm php sh -c 'vendor/bin/phpunit'
docker-compose run --user=$(UID) --rm php sh -c 'vendor/bin/phpunit'

efs: clean_all up migrate # Everything From Scratch

.PHONY: all check-style fix-style install test clean clean_all up cli installdocker migrate testdocker efs
.PHONY: all check-style fix-style install test clean clean_all up down cli installdocker migrate testdocker efs


# Docs:
Expand Down
43 changes: 1 addition & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,48 +472,7 @@ Generated files:

# Development

To contribute or play around, steps to set up this project locally are:

```bash
# in your CLI
git clone https://github.com/cebe/yii2-openapi.git
cd yii2-openapi
make clean_all
make up
make cli
composer install
make migrate

# to check everything is setup up correctly ensure all tests passes
./vendor/bin/phpunit

# create new branch from master and Happy contributing!
```

These commands are available to develop and check the tests. It is available inside the Docker container. To enter into bash shell of container, run `make cli` .

```bash
cd tests
./yii migrate-mysql/up
./yii migrate-mysql/down 4

./yii migrate-maria/up
./yii migrate-maria/down 4

./yii migrate-pgsql/up
./yii migrate-pgsql/down 4
```

To apply multiple migration with one command:

```bash
./yii migrate-mysql/up --interactive=0 && \
./yii migrate-mysql/down --interactive=0 4 && \
./yii migrate-maria/up --interactive=0 && \
./yii migrate-maria/down --interactive=0 4 && \
./yii migrate-pgsql/up --interactive=0 && \
./yii migrate-pgsql/down --interactive=0 4
```
To contribute or play around, steps to set up this project up locally are in [CONTRIBUTING.md](./CONTRIBUTING.md).


# Support
Expand Down
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
"source": "https://github.com/cebe/yii2-openapi"
},
"require": {
"php": ">=7.1.0",
"php": ">=7.2.0",
"cebe/php-openapi": "^1.5.0",
"yiisoft/yii2": "~2.0.15",
"yiisoft/yii2-gii": "~2.0.0 | ~2.1.0 | ~2.2.0| ~2.3.0",
"laminas/laminas-code": "^3.4",
"laminas/laminas-code": "^3.4 | ^4.0",
"insolita/yii2-fractal": "^1.0.0",
"fakerphp/faker": "^1.9",
"sam-it/yii2-mariadb": "^2.0"
},
"require-dev": {
"cebe/indent": "*",
"friendsofphp/php-cs-fixer": "~2.16",
"phpunit/phpunit": "^6.5|^8.0|^9.0",
"phpunit/phpunit": "^8.0",
"symfony/polyfill-php80": "^1.16",
"yiisoft/yii2-gii": ">=2.1.0"
},
"autoload": {
Expand All @@ -44,9 +45,6 @@
}
},
"config": {
"platform": {
"php": "7.1.3"
},
"allow-plugins": {
"yiisoft/yii2-composer": true
}
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
version: "3.5"
services:
php:
image: yii2-openapi-php:${PHP_VERSION:-7.4}
build:
dockerfile: tests/docker/Dockerfile
context: .
args:
- BUILD_PHP_VERSION=${PHP_VERSION:-7.4}
extra_hosts: # https://stackoverflow.com/a/67158212/1106908
- "host.docker.internal:host-gateway"
volumes:
- ./tests/tmp/.composer:/root/.composer:rw
- .:/app
Expand Down
21 changes: 12 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory>./vendor</directory>
<directory>./tests</directory>
</blacklist>
</filter>
</exclude>
</whitelist>
</filter>
</phpunit>
8 changes: 4 additions & 4 deletions src/lib/ColumnToCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ public function getCode(bool $quoted = false):string
return '$this->' . $this->fluentParts['type'];
}
if ($this->isBuiltinType) {
$parts = [
$parts = array_filter([
$this->fluentParts['type'],
$this->fluentParts['nullable'],
$this->fluentParts['default'],
$this->fluentParts['position']
];
]);
array_unshift($parts, '$this');
return implode('->', array_filter(array_map('trim', $parts), 'trim'));
return implode('->', array_filter(array_map('trim', $parts)));
}
if ($this->rawParts['default'] === null) {
$default = '';
Expand Down Expand Up @@ -508,7 +508,7 @@ public function resolvePosition()
if ($this->position === BaseMigrationBuilder::POS_FIRST) {
$this->fluentParts['position'] = 'first()';
$this->rawParts['position'] = BaseMigrationBuilder::POS_FIRST;
} elseif (strpos($this->position, BaseMigrationBuilder::POS_AFTER.' ') !== false) {
} elseif ($this->position !== null && strpos($this->position, BaseMigrationBuilder::POS_AFTER.' ') !== false) {
$previousColumn = str_replace(BaseMigrationBuilder::POS_AFTER.' ', '', $this->position);
$this->fluentParts['position'] = 'after(\''.$previousColumn.'\')';
$this->rawParts['position'] = BaseMigrationBuilder::POS_AFTER.' '.$previousColumn;
Expand Down
Loading