Skip to content

Instantly share code, notes, and snippets.

View VladaHejda's full-sized avatar

Vladislav Hejda VladaHejda

  • Slevomat
  • Czech republic
  • X @hejdav
View GitHub Profile
@VladaHejda
VladaHejda / Phpunit-Mockery_mock_ArrayAccess_Iterator_Countable-TestCase.php
Last active January 18, 2020 18:23
PHP mock ArrayAccess / Iterator / Countable. Using Phpunit with Mockery. TestCase for simple mocking classes that implements ArrayAccess, Iterator or Countable. Just create mock and call in your test: $this->mockArrayIterator($mock, $array);Notice that if you mock an interface that extends Iterator, Mockery will fail due to bug at https://github…
<?php
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected function tearDown()
{
parent::tearDown();
\Mockery::close();
}
@VladaHejda
VladaHejda / English-inflect.php
Created February 2, 2014 22:31
PHP static class for pluralizing / singularizing english words.
<?php
namespace English;
/**
* Class English\Inflect for pluralizing/singularizing english words.
*
* Thanks to http://www.eval.ca/articles/php-pluralize (MIT license)
* http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/inflections.rb (MIT license)
* http://www.fortunecity.com/bally/durrus/153/gramch13.html
@VladaHejda
VladaHejda / NetteCsvResponse.php
Last active May 29, 2017 10:37
Nette CSV response
<?php
namespace Nette\Application\Responses;
use Nette;
/**
* CSV download response.
* Under New BSD license.
*
@VladaHejda
VladaHejda / Phpunit-assert_exception.php
Last active December 28, 2022 03:59
Phpunit Exception assertion. For easy multiple testing if Exception is thrown in one test method. For PHP >= 5.5 you can use package with trait: https://packagist.org/packages/vladahejda/phpunit-assert-exception
<?php
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected function assertException(callable $callback, $expectedException = 'Exception', $expectedCode = null, $expectedMessage = null)
{
$expectedException = ltrim((string) $expectedException, '\\');
if (!class_exists($expectedException) && !interface_exists($expectedException)) {
$this->fail(sprintf('An exception of type "%s" does not exist.', $expectedException));
}
@VladaHejda
VladaHejda / phpunit.bat
Last active August 29, 2015 13:56
phpunit shortcut - can start xdebugger when -x option given
@echo off
set phpunit="C:/path/to/phpunit.phar"
if a%1==a goto noargs
if a%2==a goto noargs
if a%3==a-x goto xdebug
php %phpunit% -c %1 %2
@VladaHejda
VladaHejda / startup.bat
Last active November 24, 2016 14:09
Windows start.bat for starting choosen applications after system boot.
rem if executed at a weekday between 5 AM and 11 AM, it will start working applications
@echo off
cls
rem set your apps:
set myapp0=C:\your\app\number\one.exe
set myapp1=C:\another\app.exe
@VladaHejda
VladaHejda / OpenObject.php
Last active August 29, 2015 13:56
OpenObject let you access even protected and private properties and methods. It may be helpful for testing purposes.
<?php
/**
* OpenObject let you access even protected and private properties and methods.
* It may be helpful for testing purposes.
*/
class OpenObject
{
/** @var object */
@VladaHejda
VladaHejda / poker.php
Created May 11, 2014 09:00
Texas Hold'em Poker class. One of scripts I wrote long ago. Demonstration how I was learning OOP.
<?php
/*
Texas Hold'em Poker class
*/
require_once 'functions.php';
class poker{
@VladaHejda
VladaHejda / LazyDataMapperCache.php
Created June 2, 2014 12:55
LazyDataMapper Nette compiler extension.
<?php
namespace LazyDataMapper;
use Nette\Caching\IStorage;
use Nette\Caching\Cache as NetteCache;
class Cache implements IExternalCache
{
@VladaHejda
VladaHejda / realpathi.php
Last active July 3, 2018 03:55
PHP case-insensitive realpath()
<?php
/**
* Case-insensitive realpath()
* @param string $path
* @return string|false
*/
function realpathi($path)
{
$me = __METHOD__;