Skip to content

Instantly share code, notes, and snippets.

View minthemiddle's full-sized avatar

Martin minthemiddle

View GitHub Profile
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:05
Markdium-Lessons Learnt: Confident Laravel
assertActionUsesFormRequest(
UsersController::class, // Controller
'update', // Method
UserUpdateRequest::class); // Form Request
);
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:05
Markdium-Lessons Learnt: Confident Laravel
public function testSpying()
{
$spy = Mockery::spy();
$this->assertNull($spy->quix());
// assert behavior
$spy->shouldHaveReceived('quix')->once();
}
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:05
Markdium-Lessons Learnt: Confident Laravel
protected function setUp(): void
{
parent::setUp();
$this->subject = new UserUpdateRequest();
}
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:05
Markdium-Lessons Learnt: Confident Laravel
$mock = \Mockery::mock();
$mock->shouldReceive('info') // method name
->once()
->with('video.watched', [$video->id]);
Log::swap($mock);
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:05
Markdium-Lessons Learnt: Confident Laravel
// What is the simplest mock you can create?
class ExampleTest extends \PHPUnit\Framework\TestCase
{
public function testMocking()
{
$mock = \Mockery::mock();
$mock->shouldReceive('foo') // method name
->with('bar') // arg
->andReturn('baz'); // arg
$this->assertEquals('baz', $mock->foo('bar'));
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:05
Markdium-Lessons Learnt: Confident Laravel
class PHPUnit extends TestCase
{
public function testAssertions()
{
$this->assertTrue(true);
}
}
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:05
Markdium-Lessons Learnt: Confident Laravel
public function() {
return $this;
}
@minthemiddle
minthemiddle / 191231-failure.log
Created December 31, 2019 13:21
191231-failure
FAILURES!
Tests: 1, Assertions: 4, Failures: 1.
PHPUnit\Framework\ExpectationFailedException : Failed asserting that '<!doctype html>\n
<html lang="en">\n
<head>\n
<meta charset="utf-8">\n
<meta name="viewport" content="width=device-width, initial-scale=1">\n
\n
<!-- CSRF Token -->\n
@minthemiddle
minthemiddle / phpcs.xml
Created October 6, 2019 09:46
Laravel (5/6) config template for PHP Sniffer
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>The coding standard for this project.</description>
<rule ref="PSR2"/>
<file>app</file>
<file>bootstrap</file>
<file>config</file>
<file>database</file>
<file>resources</file>
@minthemiddle
minthemiddle / laravel-test-stub.php
Created September 17, 2019 12:06
Laravel Test Stub
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\User;
class ExampleTest extends TestCase