Skip to content

Instantly share code, notes, and snippets.

View colindecarlo's full-sized avatar

Colin DeCarlo colindecarlo

  • Guelph, Ontario, Canada
View GitHub Profile
@colindecarlo
colindecarlo / MyDateTime.php
Created March 25, 2012 16:26
Calculate the last <blank> of the month
<?php
class MyDateTime extends DateTime
{
protected $_daysOfTheWeek = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
public function lastDayOfTheMonth()
{
@colindecarlo
colindecarlo / ACDC.php
Created March 26, 2012 18:45
A class method that is both a getter and a setter
<?php
class ACDC {
protected $_data = null;
public function data()
{
$args = func_get_args();
@colindecarlo
colindecarlo / fizzbuzz.twig
Created April 17, 2012 03:06
FizzBuzz in twig
{# I was reading the twig docs this evening and decided to give good ole fizzbuzz a try #}
{% for i in range(1,100) %}
<div>
{% if i is divisibleby(15) %}
Fizzbuzz
{% elseif i is divisibleby(3) %}
Fizz
{% elseif i is divisibleby(5) %}
Buzz
@colindecarlo
colindecarlo / gist:2772887
Created May 23, 2012 02:25
persist method from the Persister abstract class
<?php
// interesting bits up here
public function persist()
{
try {
// maybe do some preprocessing of the file
// make sure it's safe, etc
@colindecarlo
colindecarlo / gist:2772976
Created May 23, 2012 02:44
protected _persist method in Persister subclass File
<?php
// interesting bits
protected function _persist()
{
$this->_location = tempnam(sys_get_temp_dir(), 'UL-');
if (!$this->_moveUploadedFile()) {
unlink($this->_location);
@colindecarlo
colindecarlo / gist:2773053
Created May 23, 2012 03:11
testing protected methods using ReflectionMethod
<?php
// interesting bits
public function test_protected_persist_directly_with_reflection_success()
{
$filePersister = new File($_FILES, $this->logger);
$reflectedPersist = new \ReflectionMethod($filePersister, '_persist');
$reflectedPersist->setAccessible(true);
@colindecarlo
colindecarlo / gist:2773074
Created May 23, 2012 03:17
the TestableFile subclass
<?php
class TestableFile extends File
{
public function _persistWrapper()
{
$this->_persist();
}
}
@colindecarlo
colindecarlo / gist:2773091
Created May 23, 2012 03:21
testing protected methods via a 'Testable' subclass
<?php
//interesting bits
public function test_protected_persist_with_testable_subclass_success()
{
$filePersister = new TestableFile($_FILES, $this->logger);
$filePersister->_persistWrapper();
$persistedLocation = \PHPUnit_Framework_Assert::readAttribute($filePersister, '_location');
@colindecarlo
colindecarlo / gist:2773143
Created May 23, 2012 03:42
testing protected method indirectly
<?php
// interesting bits
public function test_protected_persist_indirectly_via_public_persist_success()
{
$filePersister = new File($_FILES, $this->logger);
$this->assertTrue($filePersister->persist());
$persistedLocation = \PHPUnit_Framework_Assert::readAttribute($filePersister, '_location');
<?php
require_once __DIR__ . '/../scripts/bootstrap.php';
$app->get('/upload', 'Pxweb\Controller\UploadController::indexAction');
$app->post('/upload', 'Pxweb\Controller\UploadController::uploadAction');
$app->post('/sendToGoogle', 'Pxweb\Controller\GearmanController::uploadAction');
$app->get('/show/{id}', 'Pxweb\Controller\PictureController::showAction');