CategoryTechnology

All the articles related to Information Technology related fields, including programming snippets, and other things I’m interested in

PHP: Testing protected methods in CakePHP3

One of the things I recently had to deal with – PHP unit testing protected methods of the class in CakePHP 3. Few seconds of checking StackOverflow brought a nice and elegant way of checking protected methods using ReflectionClasses.

Sebastian Bergmann has a complete guide how to check non-public functionality of the classes in his archieves.

Here’s a short sample of the code using CakePHP3:

<?php
use Search\Model\Table\SaveSearchTable;
use Cake\TestSuite\TestCase;
class SaveSearchTableTest extends TestCase
{
public function setUp()
{
$this->SavedSearches = \Cake\ORM\TableRegistry::get('SavedSearches');
}
public function testProtectedMethod()
{
$methodName = 'protectedMethod';
$reflectionClass = new \ReflectionClass('\Search\Model\Table\SaveSearchesTable');
$method = $reflectionClass->getMethod($methodName);
$methodResult = $method->invokeArgs( $this->SavedSearches, ['arg1', ['arg2']]);
$this->assertNotEmpty($methodResult);
}
}

WP-CLI becomes part of make.wordpress.org

WP-CLI reached 1.x stable release. WordPress decided to make it as part of make.wordpress.org tools.

Great news from the WordPress community and those who spends most of their time in the console. No more weird sftpd/vsftpd installations.

It might come handy with composer bundle as we do it in Qobo for WordPress project templates.

PSR-7: storage-less sessions

As a frequent user of grep/ack for the codebase, ag seems to be a silver bullet, especially for the projects with large codebase. Available in rpm repositories.

What’s so great about Ag?

  • It is an order of magnitude faster than ack.
  • It ignores file patterns from your .gitignore and .hgignore.
  • If there are files in your source repo you don’t want to search, just add their patterns to a .ignore file. (*cough* *.min.js *cough*)
  • The command name is 33% shorter than ack, and all keys are on the home row!

CakeDC upgrade adds Google Authenticator

Few days of work, and almost a month of waiting. It was totally worth it. Yesterday noon, CakeDC community upgraded one of its major plugins with our Qobo patch. It allows users to enable Google Authenticator

There’s no need anymore to use ‘dev-develop’ branches in composer.

© 2018 Andy's Cave

Theme by Anders NorénUp ↑