Skip to content

Instantly share code, notes, and snippets.

@laracasts
laracasts / ApiTester.php
Last active August 29, 2015 13:58
Example
<?php
use Faker\Factory as Faker;
abstract class ApiTester extends TestCase {
/**
* @var int
*/
protected $times = 1;
@laracasts
laracasts / gist:99535e8db4298056b76d
Created May 30, 2014 19:20
Mario Kart Wii U Signups
<?= 'Add your Wii U username below'; ?>
<?php
// ...
public function store(RegistrationForm $form)
{
$form->validate(); // throws exception if fails
// save stuff
}
@laracasts
laracasts / codeception-ex.php
Last active August 29, 2015 14:04
I want an acceptance test for an Artisan command that generates some files with boilerplate. However, this command is part of a Composer package. I'm trying to figure out the best way to actually call Artisan from the package. Right now, I'm just assuming the framework and doing ../../../artisan. Is there an alternative/better way that you'd sug…
<?php
$saveDir = './tests/acceptance/tmp';
$stubDir = './tests/acceptance/stubs';
$commandToGenerate = 'FooCommand';
$I = new AcceptanceTester($scenario);
$I->wantTo('generate a command and handler class');
// Is there a better way to call the Artisan command? Without having to expect the framework and do ../../../?
/**
* Destroy the user's session (logout).
*
* @return Response
*/
public function destroy()
{
Auth::logout();
flash()->info('You are now logged out.');
@laracasts
laracasts / ex.php
Last active August 29, 2015 14:17
Working on integration testing helper for PHPUnit.
<?php
class ExampleTest extends IntegrationTest
{
/** test */
public function it_verifies_that_pages_load_properly()
{
$this->visit('/');
}
<?php
// ...
/**
* Register a decorator for the command bus.
*
* @param string $decorator
* @return CommandBus
*/
@laracasts
laracasts / gist:7628742
Created November 24, 2013 16:05
.scss vs .sass.
@mixin linear-gradient($options...) {
background: -webkit-linear-gradient($details);
background: -moz-linear-gradient($details);
background: linear-gradient($details);
}
.foo {
@include linear-gradient(top, red, green);
}
@laracasts
laracasts / ex.php
Last active January 27, 2016 13:08
So you want to allow one user to "follow" another user (like Twitter-style). Using Laravel and Eloquent, what's your preference?
<?php
// Option 1: the follow method immediately references the relationship and saves it.
class User extends Eloquent {
public function follows()
{
return $this->belongsToMany(self::class, 'follows', 'follower_id', 'followed_id');
}
@laracasts
laracasts / ApiTester.php
Created April 9, 2014 23:53
Incremental APIs: Level 9 - Tests (Readable Ones!)
<?php
use Faker\Factory as Faker;
class ApiTester extends TestCase {
/**
* @var Faker
*/
protected $fake;