Skip to content

Commit

Permalink
Merge pull request #57 from pug-php/fix/typing
Browse files Browse the repository at this point in the history
Fix #58 Handle new Symfony Twig service key
  • Loading branch information
kylekatarnls authored Dec 20, 2020
2 parents f36cc82 + bd52014 commit 8b8da19
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 49 deletions.
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Hello,

I encountered an issue when:

**Provide here exact steps and/or minimal code chunk to reproduce the issue**

Pug-Symfony version: **PUT HERE YOUR PUG-SYMFONY VERSION (exact version, not the range)**

PHP version: **PUT HERE YOUR PHP VERSION**

I expected to get:

```
Put here expected result
```

But I actually get:

```
Put here the current error/output you get instead
```

Thanks!
51 changes: 51 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Coverage

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
tests:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest']
php: ['7.4']

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

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: xdebug

- name: Install dependencies
run: composer update --prefer-dist --no-progress --no-suggest --prefer-stable ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }};

- name: Run test suite
run: vendor/bin/phpunit --verbose --coverage-text --coverage-clover=coverage.xml

- name: Code Climate Test Reporter
if: matrix.coverage
uses: aktions/codeclimate-test-reporter@v1
with:
codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
command: after-build -t clover
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
continue-on-error: true

- name: Coverage
if: matrix.coverage
run: bash <(curl -s https://codecov.io/bash)
env:
PHP_VERSION: ${{ matrix.php }}
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Tests

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
tests:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'windows-latest']
php: ['7.2', '7.3', '7.4', '8.0', '8.1']

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

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

- name: Install dependencies
run: composer update --prefer-dist --no-progress --no-suggest --prefer-stable ${{ matrix.php >= 8 && '--ignore-platform-req=php' || '' }};

- name: Run test suite
run: vendor/bin/phpunit --verbose --no-coverage
39 changes: 0 additions & 39 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pug-Symfony
[![Latest Stable Version](https://poser.pugx.org/pug-php/pug-symfony/v/stable.png)](https://packagist.org/packages/pug-php/pug-symfony)
[![Build Status](https://travis-ci.org/pug-php/pug-symfony.svg?branch=master)](https://travis-ci.org/pug-php/pug-symfony)
[![GitHub Actions](https://github.com/pug-php/pug-symfony/workflows/Tests/badge.svg)](https://github.com/pug-php/pug-symfony/actions)
[![StyleCI](https://styleci.io/repos/61784988/shield?style=flat)](https://styleci.io/repos/61784988)
[![Test Coverage](https://codeclimate.com/github/pug-php/pug-symfony/badges/coverage.svg)](https://codecov.io/github/pug-php/pug-symfony?branch=master)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "Pug template engine for Symfony",
"type": "library",
"require": {
"php": "^7.2.5",
"php": "^7.2.5 || ^8.0",
"phug/component": "^1.1.0",
"pug/installer": "^1.0.0",
"pug-php/pug": "^3.4.0",
Expand Down
3 changes: 2 additions & 1 deletion src/Pug/Symfony/Traits/HelpersHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ protected function enhanceTwig(): void
$this->twig = Environment::fromTwigEnvironment($this->twig, $this, $this->container);

$services = static::getPrivateProperty($this->container, 'services', $propertyAccessor);
$services['twig'] = $this->twig;
$key = isset($services['.container.private.twig']) ? '.container.private.twig' : 'twig';
$services[$key] = $this->twig;
$propertyAccessor->setValue($this->container, $services);
}

Expand Down
11 changes: 9 additions & 2 deletions tests/Pug/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ public function testTestInstall()
self::assertTrue(PugSymfonyEngine::install(new Event('update', new Composer(), $io), $projectDir));
self::assertSame(['Bundle added to config/bundles.php'], $io->getLastOutput());
self::assertFileExists(__DIR__.'/../../installed');
$expected = preg_replace('/(\S)\s+=>/', '$1 =>', file_get_contents(__DIR__.'/../project-s5/config/bundles.php'));
$actual = preg_replace('/(\S)\s+=>/', '$1 =>', file_get_contents("$projectDir/config/bundles.php"));
$getContent = static function (string $file): string {
return preg_replace(
'/(\S)\s+=>/',
'$1 =>',
str_replace("\r", '', file_get_contents($file))
);
};
$expected = $getContent(__DIR__.'/../project-s5/config/bundles.php');
$actual = $getContent("$projectDir/config/bundles.php");
self::assertSame($expected, $actual);

unlink(__DIR__.'/../../installed');
Expand Down
10 changes: 5 additions & 5 deletions tests/Pug/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public function setProjectDirectory(string $projectDirectory): void
$this->projectDirectory = $projectDirectory;
}

public function getLogDir()
public function getLogDir(): string
{
return sys_get_temp_dir().'/pug-symfony-log';
}

public function getRootDir()
public function getRootDir(): string
{
return realpath(__DIR__.'/../project-s5');
}
Expand All @@ -57,14 +57,14 @@ public function getRootDir()
*
* @throws Exception
*/
public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);
$loader->load(__DIR__.'/../project-s5/config/packages/framework.yaml');
$loader->load($this->containerConfigurator);
}

public function getCacheDir()
public function getCacheDir(): string
{
return sys_get_temp_dir().'/pug-symfony-cache';
}
Expand All @@ -73,7 +73,7 @@ public function getCacheDir()
* Override the parent method to force recompiling the container.
* For performance reasons the container is also not dumped to disk.
*/
protected function initializeContainer()
protected function initializeContainer(): void
{
$this->container = $this->buildContainer();
$this->container->compile();
Expand Down

0 comments on commit 8b8da19

Please sign in to comment.