Skip to content

Instantly share code, notes, and snippets.

View coreymcmahon's full-sized avatar

Corey McMahon coreymcmahon

View GitHub Profile
<?php
class PostController
{
public function index()
{
$posts = Post::where('date', '>', Carbon::now()->subDays(7))->get();
return View::make('users.show', compact('posts'));
}
// ...
<?php
class PostRepository
{
public function getRecent()
{
return Post::where('date', '>', Carbon::now()->subDays(7))->get();
}
public function getRecentFor($user_id)
@coreymcmahon
coreymcmahon / ServiceLayerExample.php
Created July 18, 2014 04:57
Example of using a service layer w/ the repository pattern - www.slashnode.com
<?php
/* UserRepository.php */
namespace Acme\Repositories;
class UserRepository extends AbstractRepository implements UserRepositoryInterface
{
// etc...
}
@coreymcmahon
coreymcmahon / FeatureContext.php
Created July 12, 2014 08:32
Mocking the Filesystem during BDD with Behat and PHPSpec - www.slashnode.com
<?php
/** ... etc ... */
class FeatureContext implements SnippetAcceptingContext
{
protected $filesystem;
protected $config;
protected $sut;
@coreymcmahon
coreymcmahon / config.feature
Created July 12, 2014 08:17
Mocking the Filesystem during BDD with Behat and PHPSpec - www.slashnode.com
Feature: Configuration Files
In order to configure my application
As a developer
I need to be able to store configuration options in a file
Scenario: Getting a configured option
Given there is a configuration file
And the option 'timezone' is configured to 'UTC'
When I load the configuration file
Then I should get 'UTC' as 'timezone' option
@coreymcmahon
coreymcmahon / FeatureContext.php
Created July 12, 2014 08:16
Mocking the Filesystem during BDD with Behat and PHPSpec - www.slashnode.com
<?php
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use org\bovigo\vfs\vfsStream;
/**
@coreymcmahon
coreymcmahon / ConfigSpec.php
Created July 12, 2014 08:15
Mocking the Filesystem during BDD with Behat and PHPSpec - www.slashnode.com
<?php
namespace spec;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ConfigSpec extends ObjectBehavior
{
function it_is_initializable()
@coreymcmahon
coreymcmahon / Config.php
Created July 12, 2014 08:13
Mocking the Filesystem during BDD with Behat and PHPSpec - www.slashnode.com
<?php
class Config
{
protected $settings;
public function __construct($settings = array())
{
$this->settings = $settings;
}
@coreymcmahon
coreymcmahon / start.php
Created May 22, 2014 06:31
Setting the environment name in Laravel using an environment variable - http://www.slashnode.com
<?php
// ... etc
// in bootstrap/start.php
$env = $app->detectEnvironment(function ()
{
return getenv('APP_ENV');
});
@coreymcmahon
coreymcmahon / start.php
Created May 22, 2014 06:27
Using a config file to define the environment name in Laravel - http://www.slashnode.com
<?php
// ... etc
// in bootstrap/start.php
$env = $app->detectEnvironment(function ()
{
return require __DIR__.'/environment.php';
});