This document provides information on various tools and best practices for PHP development. It discusses code quality tools like PHP CodeSniffer, PHP Mess Detector and PHPStan that can be used for static analysis and linting. It also covers code standards like PSR-1 and PSR-2, testing tools like PHPUnit and tools for continuous integration like Travis CI.
46. Unit Test
—
Class method
# Class
class LinkerTest extends TestCase
{
public function testAutolink()
{
// arrange
$text = '...';
$target = new Linker();
$expected = '...';
// act
$actual = $target->autolink($text);
// assert
$this->assertEquals($expected, $actual);
}
}
49. Feature Test
—
# Class
class PostController extends Controller
{
public function store(Request $request)
{
Post::create($request->all());
return redirect()->route('...')
->with('message', 'Success');
}
}
50. Feature Test
—
# Class
class PostControllerTest extends TestCase
{
use RefreshDatabase;
use WithoutMiddleware;
public function testPostStoreAction()
{
$data = [
'title' => '...',
'content' => '...',
];
$response = $this->post('...', $data);
$response->assertRedirect('...');
$this->assertDatabaseHas('...', $data);
}
}
63. Continuous integration
—
CI
• / /
• /
• /
CI
• CI
• CI
• CI
Image from: http://www.seleniumeasy.com/jenkins-tutorials/what-is-continous-integration
64. CI
—
StyleCI Nitpick CI CI
CI phpdbf php-
cs-fixer
https://styleci.io/
https://nitpick-ci.com/