Vitor Mattos
Realizador de sonhos desde 2003
Amante de opensource
Palestrante
PHP Zend Certified Engineer ( ZEND024235 )
PHPRio ( https://telegram.me/phprio )
CTO LibreCode
Redes sociais: ( VitorMattos ou VitorMattosRJ )
git clone https://github.com/vitormattos/api-test
cd api-test
# PRESENTING CODE
# PRESENTING CODE
Com docker
docker-compose up
# PRESENTING CODE
Sem docker
php -S 0.0.0.0:8080 -t public
# Endpoints
Verbo | Endpoint | Body |
---|---|---|
GET | /api/user | |
POST | /api/user | {"name": "oi","id":1} |
DELETE | /api/user/{id} |
Objetivo: Manipular arquivo storage/database.json
composer require --dev squizlabs/php_codesniffer
# PRESENTING CODE
PSR
vendor/bin/phpcs
# PRESENTING CODE
PSR
vendor/bin/phpcs --standard=PSR12 -n src -n public
# PRESENTING CODE
PSR
"scripts" : {
"phpcs" : "phpcs --standard=PSR12 -n src"
}
# PRESENTING CODE
PSR
composer.json
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer">
<description>The coding standard for PHP_CodeSniffer itself.</description>
<arg name="colors"/>
<file>./src</file>
<file>./public</file>
<rule ref="PSR12"></rule>
</ruleset>
# PRESENTING CODE
.phpcs.xml, phpcs.xml, .phpcs.xml.dist, phpcs.xml.dist
Config file
composer require --dev vimeo/psalm
./vendor/bin/psalm --init
# PRESENTING CODE
install
./vendor/bin/psalm
# PRESENTING CODE
Verificando
./vendor/bin/psalm --show-info=true
Verificando com mais detalhes
"scripts" : {
"phpcs" : "phpcs",
"phpcbf" : "phpcbf",
"psalm" : "psalm",
"test" : [
"@phpcs",
"@psalm"
]
}
# PRESENTING CODE
composer.json
composer require --dev phpstan/phpstan
# PRESENTING CODE
install
"scripts" : {
"phpcs" : "phpcs",
"phpcbf" : "phpcbf",
"psalm" : "psalm",
"phpstan" : "phpstan analyse src --level 5",
"test" : [
"@phpcs",
"@psalm",
"@phpstan"
]
}
# PRESENTING CODE
composer.json
Levels: 0-9
# PRESENTING CODE
Requer extensão, setup mais complexo
# PRESENTING CODE
# PRESENTING CODE
Tem documentação em português
# PRESENTING CODE
composer require --dev phpunit/phpunit
mkdir tests
# PRESENTING CODE
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class UserControllerTest extends TestCase
{
public function testTrue(): void
{
$this->assertTrue(true);
}
}
tests/unit/Controller/UserControllerTest.php
# PRESENTING CODE
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests/Unit</directory>
<directory suffix="Test.php">tests/Doc</directory>
</testsuite>
<testsuite name="unit">
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
<testsuite name="doc">
<directory suffix="Test.php">tests/Doc</directory>
</testsuite>
</testsuites>
Configure: phpunit.xml
# PRESENTING CODE
run
vendor/bin/phpunit --testsuite unit
# PRESENTING CODE
composer require --dev behat/behat
vendor/bin/behat --init
install
# PRESENTING CODE
composer require --dev byjg/swagger-test
install
# PRESENTING CODE
vendor/bin/phpunit --testsuite doc
run
# PRESENTING CODE
name: Psalm
on: pull_request
jobs:
psalm:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['8.1', '8.2']
name: psalm check php${{ matrix.php-versions }}
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up php
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-versions }}
coverage: none
- name: Install dependencies
run: composer i
- name: Run coding standards check
run: composer psalm
“Eu cheguei a seguinte conclusão: não adianta consertar o resto, conserta a gente ajuda pra caramba”
Renato Russo
Que país é esse?
Redes sociais:
( VitorMattos ou VitorMattosRJ )