Skip to content

Instantly share code, notes, and snippets.

@mnapoli
mnapoli / SchemaValidationTest.php
Created December 10, 2012 09:56
Doctrine schema validation in a PHPUnit test
<?php
/**
* @author Matthieu Napoli
* @link http://en.mnapoli.fr/doctrine-schema-validation-in-a-phpunit-test/
* @license WTFPL - Do What The Fuck You Want To Public License (http://sam.zoy.org/wtfpl/)
*/
use Doctrine\ORM\Tools\SchemaValidator;
/**

Usage:

php script.php test.plt

Sample output:

G01 X-7626 Y-392 Z0
#!/bin/bash
set -e
cd /tmp
echo "Installing PHP"
#mkdir /tmp/php
#curl -sSL https://s3-eu-west-1.amazonaws.com/mnapoli/test-aws/php.tar.gz | tar -xz -C /tmp/php
@mnapoli
mnapoli / README.md
Last active December 8, 2016 14:42
Extended callables

PHP callables

Those are callables recognized by PHP natively. They can be invoked simply: $callable(...).

  • Closures: function () { ... }

  • Static method call: ['A', 'staticMethod'] or also Foo::staticMethod

    class A {

public static function staticMethod() { ... }

@mnapoli
mnapoli / .phpstorm.meta.php
Created July 1, 2016 11:36
PHPUnit autocompletion with PhpStorm's latest EAP
<?php
namespace PHPSTORM_META {
$STATIC_METHOD_TYPES = [
\PHPUnit_Framework_TestCase::createMock('') => [
"" == "@|PHPUnit_Framework_MockObject_MockObject",
],
\PHPUnit_Framework_TestCase::getMock('') => [
"" == "@|PHPUnit_Framework_MockObject_MockObject",
],
@mnapoli
mnapoli / iterable.md
Last active July 3, 2016 20:06
Iterable
can be used with foreach(… array_*(…) functions yield from … array type-hint Traversable type-hint can be implemented
array
Traversable
iterable
@mnapoli
mnapoli / PHP-DI 6.md
Last active March 15, 2016 22:11
PHP-DI 6

PHP-DI 6 ideas

Main changes:

Rename a few helpers to actions:

  • factory() -> call()
  • object() -> create()

This is hopefully clearer on what will actually be done.

<?php
namespace TwigModule;
use Interop\Container\ContainerInterface;
use Interop\Container\ServiceProvider\ServiceProvider;
use Puli\Repository\Api\ResourceRepository;
use Puli\TwigExtension\PuliExtension;
use Puli\TwigExtension\PuliTemplateLoader;
use Puli\UrlGenerator\Api\UrlGenerator;
@mnapoli
mnapoli / gist:7471722
Created November 14, 2013 18:21
Factory methods
<?php
class Image
{
private $width;
private $height;
private $content;
public static function createEmpty($width, $height, $bgcolor = null)
{
@mnapoli
mnapoli / gist:6988778
Last active December 25, 2015 14:09
Anonymous classes FTW
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testSomeStuff()
{
// Build my mock
$mock = new class extends CrawlerInterface {
public function crawl($url) {
return ['some', 'data'];