Skip to content

Commit

Permalink
Allow nulled layout, 100% test coverage and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 18, 2020
1 parent beb9edd commit f897e6e
Show file tree
Hide file tree
Showing 19 changed files with 471 additions and 106 deletions.
54 changes: 19 additions & 35 deletions .github/workflows/build.yml
Expand Up @@ -6,9 +6,9 @@ name: build

jobs:
tests:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
name: PHP ${{ matrix.php }}-${{ matrix.os }}

env:
extensions: curl, mbstring, dom, intl, json, libxml, xml, xmlwriter
key: cache-v1

runs-on: ${{ matrix.os }}
Expand All @@ -19,72 +19,56 @@ jobs:
- ubuntu-latest
- windows-latest

php-version:
php:
- "7.4"
- "8.0"

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
uses: actions/checkout@v2.3.4

- name: Install PHP with extensions
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
php-version: ${{ matrix.php }}
ini-values: date.timezone='UTC'
coverage: pcov
tools: composer:v2

- name: Determine composer cache directory on Linux
if: matrix.os == 'ubuntu-latest'
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Determine composer cache directory on Windows
if: matrix.os == 'windows-latest'
run: ECHO "::set-env name=COMPOSER_CACHE_DIR::~\AppData\Local\Composer"
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Install dependencies with composer php 7.4
if: matrix.php-version == '7.4'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
if: matrix.php == '7.4'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install dependencies with composer php 8.0
if: matrix.php-version == '8.0'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader
if: matrix.php == '8.0'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit and coverage on Linux php 7.4
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
run: vendor/bin/phpunit --coverage-clover=coverage.clover
if: matrix.os == 'ubuntu-latest' && matrix.php == '7.4'
run: vendor/bin/phpunit --coverage-clover=coverage.clover --colors=always

- name: Run tests with phpunit without coverage
if: matrix.os != 'ubuntu-latest' || matrix.php-version != '7.4'
run: vendor/bin/phpunit
if: matrix.os != 'ubuntu-latest' || matrix.php != '7.4'
run: vendor/bin/phpunit --colors=always

- name: Upload code coverage scrutinizer on Linux php 7.4
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
if: matrix.os == 'ubuntu-latest' && matrix.php == '7.4'
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
31 changes: 14 additions & 17 deletions .github/workflows/mutation.yml
Expand Up @@ -8,48 +8,45 @@ name: mutation test

jobs:
mutation:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}

name: PHP ${{ matrix.php }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php-version:
php:
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: Checkout
uses: actions/checkout@v2.3.4

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
php-version: "${{ matrix.php }}"
ini-values: memory_limit=-1
coverage: "pcov"
tools: composer:v2

- name: Determine composer cache directory
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run test mutation infection with coverage
- name: Run infection
run: |
mkdir -p build/logs
vendor/bin/phpunit --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit.xml
vendor/bin/infection --threads=2 --coverage=build/logs --show-mutations --no-progress --min-msi=10 --min-covered-msi=10
git fetch --depth=1 origin $GITHUB_BASE_REF
vendor/bin/roave-infection-static-analysis-plugin -j2 --git-diff-filter=A --git-diff-base=origin/$GITHUB_BASE_REF --logger-github --ignore-msi-with-no-mutations --only-covered
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
29 changes: 12 additions & 17 deletions .github/workflows/static.yml
Expand Up @@ -6,45 +6,40 @@ name: static analysis

jobs:
mutation:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
env:
extensions: ast

name: PHP ${{ matrix.php }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php-version:
php:
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: Checkout
uses: actions/checkout@v2.3.4

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
extensions: ${{ env.extensions }}
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis with psalm
- name: Static analysis
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize
9 changes: 5 additions & 4 deletions composer.json
Expand Up @@ -28,12 +28,13 @@
"yiisoft/view": "^3.0@dev"
},
"require-dev": {
"infection/infection": "^0.16.3",
"nyholm/psr7": "^1.3",
"vimeo/psalm": "^3.15",
"phpunit/phpunit": "^9.3",
"phpunit/phpunit": "^9.4",
"roave/infection-static-analysis-plugin": "^1.4",
"vimeo/psalm": "^4.1",
"yiisoft/di": "^3.0@dev",
"yiisoft/event-dispatcher": "^3.0@dev"
"yiisoft/event-dispatcher": "^3.0@dev",
"yiisoft/test-support": "3.0.x-dev"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion src/ContentParametersInjectionInterface.php
Expand Up @@ -6,7 +6,6 @@

interface ContentParametersInjectionInterface
{

/**
* Returns parameters for added to content.
*
Expand Down
1 change: 0 additions & 1 deletion src/LayoutParametersInjectionInterface.php
Expand Up @@ -6,7 +6,6 @@

interface LayoutParametersInjectionInterface
{

/**
* Returns parameters for added to layout.
*
Expand Down
1 change: 0 additions & 1 deletion src/LinkTagsInjectionInterface.php
Expand Up @@ -6,7 +6,6 @@

interface LinkTagsInjectionInterface
{

/**
* Returns array of link tags for register via {@see \Yiisoft\View\WebView::registerLinkTag()}.
* Optionally, you may set the key that identifies the link tag via `__key`.
Expand Down
1 change: 0 additions & 1 deletion src/MetaTagsInjectionInterface.php
Expand Up @@ -6,7 +6,6 @@

interface MetaTagsInjectionInterface
{

/**
* Returns array of meta tags for register via {@see \Yiisoft\View\WebView::registerMetaTag()}.
* Optionally, you may set the key that identifies the meta tag via `__key`.
Expand Down
35 changes: 6 additions & 29 deletions src/ViewRenderer.php
Expand Up @@ -14,14 +14,13 @@

final class ViewRenderer implements ViewContextInterface
{

private DataResponseFactoryInterface $responseFactory;
private Aliases $aliases;
private WebView $view;
private CsrfViewInjection $csrfViewInjection;

private string $viewBasePath;
private string $layout;
private ?string $layout;
private array $injections;

private ?string $name = null;
Expand All @@ -33,7 +32,7 @@ public function __construct(
WebView $view,
CsrfViewInjection $csrfViewInjection,
string $viewBasePath,
string $layout,
?string $layout = null,
array $injections = []
) {
$this->responseFactory = $responseFactory;
Expand Down Expand Up @@ -73,67 +72,45 @@ public function withController(object $controller): self
{
$new = clone $this;
$new->name = $this->extractControllerName($controller);

return $new;
}

public function withControllerName(string $name): self
{
$new = clone $this;
$new->name = $name;

return $new;
}

public function withViewPath(string $viewPath): self
{
$new = clone $this;
$new->viewPath = $viewPath;

return $new;
}

public function withViewBasePath(string $viewBasePath): self
{
$new = clone $this;
$new->viewBasePath = $viewBasePath;

return $new;
}

public function withLayout(string $layout): self
public function withLayout(?string $layout): self
{
$new = clone $this;
$new->layout = $layout;

return $new;
}

/**
* @param object[] $injections
* @return self
*/
public function withAddedInjections(array $injections): self
public function withAddedInjections(object ...$injections): self
{
$new = clone $this;
$new->injections = array_merge($this->injections, $injections);
return $new;
}

/**
* @param object $injection
* @return self
*/
public function withAddedInjection(object $injection): self
{
return $this->withAddedInjections([$injection]);
}

/**
* @param object[] $injections
* @return self
*/
public function withInjections(array $injections): self
public function withInjections(object ...$injections): self
{
$new = clone $this;
$new->injections = $injections;
Expand All @@ -142,7 +119,7 @@ public function withInjections(array $injections): self

public function withCsrf(): self
{
return $this->withAddedInjection($this->csrfViewInjection);
return $this->withAddedInjections($this->csrfViewInjection);
}

private function renderProxy(string $view, array $parameters = []): string
Expand Down
Empty file removed tests/.gitkeep
Empty file.

0 comments on commit f897e6e

Please sign in to comment.