Skip to content

Instantly share code, notes, and snippets.

View tomphp's full-sized avatar

Tom Oram tomphp

View GitHub Profile
func! PhpRefactorShowMenu()
echohl Title
echo 'Available Refactorings:'
echohl None
echo '(em) Extract Method'
echo '(lv) rename Local Variable'
echo '(li) Local variable to Instance variable'
echo '(ou) Optimize Use'
echo ''
echo '(c) Cancel'
<?php
class TestClassSpec extends ObjectBehavior
{
public function it_runs_action1(ActionClass $action) {
$action->action1()->shouldBeCalled();
// I have to add this here even though it is not the focus of this test?
$action->action2()->shouldBeCalled();
<?php
// Problem:
// I'm testing a method which adds a service to a service container class which takes a service
// name and a callback which creates the service. Like so:
function load(ServiceContainer $container)
{
$container->set(
'event_dispatcher.listeners.db_extension',
@tomphp
tomphp / ob1saver.php
Last active August 29, 2015 13:58
Interface typing
<?php
/*
* Since we don't have method over loading, shouldn't this be possible?
*/
interface Object1Saver
{
public function save(Object1 $obj);
}
<?php
/*
* Say you have an entity class which has no need to expose its internal data
* fields in the business layer like so:
*/
class LibraryBook
{
/** @var string */
@tomphp
tomphp / closure-test.php
Last active August 29, 2015 14:06
Testing Closures
<?php
interface Item
{
public function runAction();
}
interface SomeCollection
{
public function foreachItem(callable $fn);
@tomphp
tomphp / gist:7cebee49783f8f13a314
Last active August 29, 2015 14:07
Clojure Value Objects
// Given
(defn make-customer [name email]
{:name name, :email email})
// Examples
(def customer1 (make-customer "Tom" "email@address.com"))
// vs...
Feature: View a widget
# Approach 1
Scenario: View a widget's attributes
Given there is a widget named "the widget" with attribute1 "attr 1 val" and attribute2 "attr 2 val" and attribute3 "attr 3 val"
Then the widget named "the widget" should have attribute1 value "attr 1 val" and attribute2 value "attr 2 val" and attribute3 "attr 3 val"
# Approach 2
Scenario: View a widget's attributes
Given there is a widget named "the widget"
@tomphp
tomphp / gist:aa988344c4a77d52b3d5
Last active August 29, 2015 14:18
Example of navigating HAL APIs
<?php
// An example of navigating HAL enabled JSON APIs in Behat tests
// using https://github.com/tomphp/hal-client
use TomPHP\HalClient\Client;
class APIContext
{
// ...
@tomphp
tomphp / example.php
Created January 14, 2016 21:21
Example of tomphp/transform __() function
<?php
// https://github.com/tomphp/php-transform
use function TomPHP\Transform\__;
$ticket1 = new Ticket(new User(['dob' => new DateTime('1980-01-22')]));
$ticket2 = new Ticket(new User(['dob' => new DateTime('1984-08-08')]));
$tickets = [$ticket1, $ticket2];