Posts

Showing posts from August, 2013

Make Your phpUnit Tests Run Faster by Sharing Fixtures

Image
There are few good reasons why you may want to share the fixtures between test, and most of the time the reason could be a bad design. For example, you would like to use share database connections, but your database adapter does not implement Singleton pattern . In order to take advantage of sharing fixtures between tests within single Test Case, your test case should implement two public static methods setUpBeforeClass() and tearDownAfterClass() , and shared fixture itself should be protected static variable. Following example shows sharing database fixture between tests: <?php class DatabaseTest extends PHPUnit_Framework_TestCase { protected static $dbh; public static function setUpBeforeClass() { self::$dbh = new PDO('sqlite::memory:'); } public static function tearDownAfterClass() { self::$dbh = NULL; } public function testShouldReturnCountGreaterThanZero() { $cmd = self::$dbh->prepare('SELEC...

10gen Announces Company Name Change to MongoDB, Inc.

Image
New York—August 27, 2013—10gen, the MongoDB company, today announced it is changing its name to MongoDB, Inc. The new name more closely unifies the open-source database project with the company behind it. The change is effective immediately. “In 2007, 10gen began work on an open-source cloud computing stack. That was the birth of MongoDB, as the data layer of that platform,” said Dwight Merriman, Chairman and Co-founder at 10gen. “When we saw the potential for the database we had built we decided to focus 100% on MongoDB. Thus the company name 10gen and the database name MongoDB were different. With this change, our goal is to get the names back into alignment.” The MongoDB project, and its mongodb.org community website, are unaffected by this change. 10gen will change its corporate website from 10gen.com to mongodb.com . As part of today’s announcement, 10gen Education, which provides free, online training as well as public and private in-person courses, has been rebranded MongoD...

Stubbing and Mocking Static Methods with PHPUnit

Image
PHPUnit has ability to stub and mock static methods. Consider the class Foo : <?php class Foo { public static function doSomething() { return static::helper(); } public static function helper() { return 'foo'; } } ?> To test the static helper() function with PHPUnit, you can write you test like that: <?php class FooTest extends PHPUnit_Framework_TestCase { public function testDoSomething() { $class = $this->getMockClass( 'Foo', /* name of class to mock */ array('helper') /* list of methods to mock */ ); $class::staticExpects($this->any()) ->method('helper') ->will($this->returnValue('bar')); $this->assertEquals( 'bar', $class::doSomething() ); } } ?> The new staticExpects() method works similar to the non-static expects...

Finding project files containing console.log()

Image
Found this little snippet online and modified for my own purposes. The goal was to find all template and PHP files containing console.log() operations, left in by other developers and programmers for debugging purposes. You don't want to have these files in your production environment, therefore before committing your code you could (with little modifications) add this to your pre-commit git hook and refuse commit if certain files contain console.log(). egrep -lir --include=*.{php,phtml,tpl} "(console\.log\()" . Following command will find all PHP, PHTML and TPL files in current folder which contain string  console.log( It will simply list all the files. You could pipe it with " | wc -l" to get counts.

View Manual Webspam Actions in Webmaster Tools

Image
From  Official Google Webmaster Central Blog: View manual webspam actions in Webmaster Tools : Webmaster level: All We strive to keep spam out of our users’ search results. This includes both improving our webspam algorithms as well as taking manual action for violations of Google's quality guidelines. In case you have noticed, there is new link under Search Traffic  called Manual Actions . If you click on it, and find message stating "No manual webspam actions found." then congrats, you have done everything right. A recent analysis of Google index showed that well under 2% of domains are manually removed for webspam. If you are one of the few unlucky who do have manual spam action, you probably have message in your inbox (and Google keeps sending these until you take appropriate actions). Here’s what it would look like if Google had taken manual action on a specific section of a site for "User-generated spam": According to Google, Once you’ve ...