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 / 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 / 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:13
Snippet from helloTestableTest.php
<?php
public function testEchoLyric()
{
$mockLyric = new \MockLyric('foobar');
$hello = new helloTestable($mockLyric);
$this->expectOutputRegex('/.*foobar*./');
$hello->echoLyric();
}
@eriktorsner
eriktorsner / helloTestableTest.php
Last active April 25, 2017 10:13
Snippet from helloTestableTest.php
<?php
public function testEchoCss()
{
\WP_Mock::userFunction('is_rtl', array(
'return_in_order' => array(true, false),
));
$dummy = new \stdClass();
$hello = new helloTestable($dummy);
@eriktorsner
eriktorsner / RuntimeProviderTest.php
Last active April 25, 2017 10:12
Snippet from RuntimeProviderTest.php
<?php
public function testRegister()
{
$container = new Pimple\Container();
$provider = new RuntimeProvider();
$provider->register($container);
$this->assertInstanceOf('helloTestable\Lyrics', $container['lyrics']);
$this->assertInstanceOf('helloTestable\helloTestable', $container['helloTestable']);
@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 / 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";