Skip to content

Instantly share code, notes, and snippets.

View eriktorsner's full-sized avatar

Erik Torsner eriktorsner

  • Stockholm, Sweden
View GitHub Profile
@eriktorsner
eriktorsner / MockObjects.php
Last active April 25, 2017 10:13
helloTestable MockObjects.php
<?php
class MockLyric
{
public function __construct($lyric)
{
$this->lyric = $lyric;
}
public function getLyric()
@eriktorsner
eriktorsner / helloTestableTest.php
Last active April 25, 2017 10:14
Snippet from helloTestableTest.php
<?php
public function testInit()
{
$dummy = new \stdClass();
$hello = new helloTestable($dummy);
\WP_Mock::expectActionAdded('admin_notices', array($hello, 'echoLyric'));
\WP_Mock::expectActionAdded('admin_head', array($hello, 'echoCss'));
@eriktorsner
eriktorsner / LyricsTest.php
Last active April 25, 2017 10:14
Snippet from LyricsTest.php
<?php
public function testGetLyric()
{
$file = dirname(__DIR__) . '/fixtures/lyrics.txt';
$lyrics = new Lyrics($file);
\WP_Mock::userFunction('wptexturize', array(
'return' => function($s) {
return $s . ' wptexturize';
@eriktorsner
eriktorsner / helloTestable.php
Created April 25, 2017 10:06
Snippet 3 from helloTestable.php
<?php
/**
* Output the lyric string
*/
public function echoLyric()
{
$lyricString = $this->lyrics->getLyric();
echo "<p id='dolly'>$lyricString</p>";
}
@eriktorsner
eriktorsner / helloTestable.php
Created April 25, 2017 10:05
Snippet 2 from helloTestable.php
<?php
/**
* Hook up our plugin with WordPress
*/
public function init()
{
add_action('admin_notices', array($this, 'echoLyric'));
add_action('admin_head', array($this, 'echoCss'));
}
@eriktorsner
eriktorsner / helloTestable.php
Last active April 25, 2017 10:05
Snippet 1 helloTestable.php
<?php
/**
* helloTestable constructor.
*
* @param Lyrics $lyrics
*/
public function __construct($lyrics)
{
$this->lyrics = $lyrics;
@eriktorsner
eriktorsner / Lyrics.php
Created April 25, 2017 10:03
Snippet from Lyrics.php
<?php
/**
* Class Lyrics
* A class to encapsulate lyrics for a song
*
* @package helloTestable
*/
class Lyrics
{
/**
@eriktorsner
eriktorsner / RuntimeProvider.php
Last active December 27, 2017 10:06
Snippet from RuntimeProvider.php
<?php
/**
* Class RuntimeProvider
*
* Use Pimple as dependency injection container
*
*/
class RuntimeProvider implements ServiceProviderInterface
{
/**
@eriktorsner
eriktorsner / hello-bootstrap.php
Last active April 25, 2017 23:59
Snippet from hello-bootstrap.php
<?php
/**
* The main plugin function. Checks php version
* and initialize our classes
*/
function helloTestableBootstrap()
{
$pluginVersion = '0.1.0';
if (defined('DOING_AJAX') && DOING_AJAX) {
return;
@eriktorsner
eriktorsner / critcss.snippet.js
Last active November 11, 2016 11:02 — forked from james-Ballyhoo/critcss.snippet.js
Based off of https://gist.github.com/PaulKinlan/6284142 , but with support for media queries and dumps css to a textarea in a panel stuck to the top of the page. Only tested in Chrome, uses height of window to determine "critical path".
(function(){
if(document.querySelector("#_CRIT_CSS")){return;}
var container = document.createElement("div");
container.id = "_CRIT_CSS";
container.innerHTML = '<textarea cols=80 rows=20></textarea><button id="CRIT_FIND">Find Critical CSS</button><button id="CRIT_CLOSE">Exit</button>';
container.style.position = "fixed";
container.style.top = 0;
container.style.left = 0;
container.style.right = 0;
container.style.backgroundColor = "#FFF";