Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link rel="stylesheet" href="theme.css" type="text/css" />
</head>
<body>
@mvriel
mvriel / pre-commit.php
Created May 16, 2011 20:14
Pre-commit hook for DocBlox
#!/usr/bin/php
<?php
echo PHP_EOL;
// output a little introduction
echo '>> Starting unit tests' . PHP_EOL;
// get the name for this project; probably the topmost folder name
$projectName = basename(getcwd());
@mvriel
mvriel / gist:1387152
Created November 22, 2011 21:59
RFC: Adding support for external artifacts for Travis

In order to display the output of several source code analysis / build tools it is necessary to have the ability to store and display their output.

QA Tools can output in two different ways:

  • To STDOUT
  • To a physical disk as file(s)

The latter output type can be split into two sub-types:

  • Raw files, or logs
@mvriel
mvriel / gist:1548455
Created January 1, 2012 21:57
Extract dependency namespaces from DocBlox structure file and attempt to generate composer.json requires
<?php
if ($argc < 2) {
throw new Exception('Must provide location of DocBlox structure.xml file as argument');
}
$structure_file = $argv[1];
$packages = array();
$packagist = json_decode(file_get_contents('http://packagist.org/packages.json'));
foreach($packagist as $package_obj) {
@mvriel
mvriel / gist:3822861
Created October 2, 2012 19:49
Option arrays in PHPDoc
<?php
/*
This code sample demonstrates several style for representing an option array with
the following fields: name, label, type_id, visible, default.
When designing this we should keep in mind that the option key may be represented
by either a literal or a (class)constant. As such we mix and match those for
illustrative purposes.
*/
@mvriel
mvriel / gist:3823010
Created October 2, 2012 20:14
Generic notation in PHPDoc vs. plain array notation
<?php
/**
* @template <T> The type of the individual elements
*/
class ArrayCollection implements IteratorAggregate
{
private $elements;
/**
* @param array<T> $elements
Class IpRange
{
public function setStartingAddress($startingAddress)
{
InputValidator::assertValidAddress($startingAddress);
$this->startingAddress = (int) $startingAddress;
return $this;
}
}
@mvriel
mvriel / media.php
Last active December 22, 2015 07:59 — forked from brichards/media.php
<?php
/**
* Override default image downsize rules with a custom resizing service
*
* Defaults to false (no third-party downsizing), but can be overriden with an indexed
* array of image details to use in place of WP's default downsizing rules.
*
* @since 2.5.0
*
@mvriel
mvriel / gist:c811f7996ed28b478bf9
Created September 4, 2014 07:30
Mocking two invocations of one call with different arguments
<?php
$resolverMock = m::mock('Symfony\Component\OptionsResolver\OptionsResolver');
$resolverMock->shouldReceive('setNormalizers');
$resolverMock->shouldReceive('setAllowedTypes');
$resolverMock->shouldReceive('setDefaults')->atMost()->once()->withAnyArgs();
$resolverMock->shouldReceive('setDefaults')->atLeast()->once()->with(
array(
'label' => 'MyLabel',
'choices' => array(
'1' => 'Option1',
@mvriel
mvriel / MyClass.php
Created September 4, 2014 09:44
Why does my test not fail on the second mockedMethod call?
<?php
class MyClass
{
public function test($dependency)
{
$dependency->mockedMethod('I have random arguments');
$dependency->mockedMethod(
array(
'choices' => array(