Skip to content

Instantly share code, notes, and snippets.

@indrekots
indrekots / ParentModel.php
Created October 11, 2013 09:34
Defining a "has many" relation with Yii's Active Record
<?php
...
public function relations() {
return array(
'childModels' => array(self::HAS_MANY, 'ChildModel', 'parent_model_id')
);
}
...
@indrekots
indrekots / ParentModel.php
Created October 11, 2013 09:48
Defining a "has many" relation with Yii's namespaced Active Record
<?php
...
public function relations() {
return array(
'childModels' => array(self::HAS_MANY, 'application\models\ChildModel', 'parent_model_id')
);
}
...
@indrekots
indrekots / ChildModel.php
Created October 11, 2013 09:50
Defining a "belongs to" relation with Yii's namespaced Active Record
<?php
...
public function relations() {
return array(
'ParentModel' => array(self::BELONGS_TO, 'application\models\ParentModel', 'parent_model_id')
);
}
...
@indrekots
indrekots / HelloJob.php
Last active December 25, 2015 21:09
Sample job class using php-resque
<?php
class HelloJob implements Job
{
public function perform()
{
echo "Hello world";
}
}
@indrekots
indrekots / Job.php
Last active December 25, 2015 21:09
Interface for job classes when using php-resque
<?php
/**
* Defines a php-resque job
*/
interface Job
{
/**
* Executes the job
@indrekots
indrekots / resque.php
Created October 21, 2013 08:23
Enqueueing a job with Resque and PHP
<?php
Resque::enqueue("default", 'application\models\jobs\TestJob', array("arg1" => "myArg1");
@indrekots
indrekots / default-filters.php
Last active December 27, 2015 02:19
A section from the default-filters.php file in Wordpress
<?php
// Display filters
add_filter( 'the_title', 'wptexturize' );
add_filter( 'the_title', 'convert_chars' );
add_filter( 'the_title', 'trim' );
add_filter( 'the_content', 'wptexturize' );
add_filter( 'the_content', 'convert_smilies' );
add_filter( 'the_content', 'convert_chars' );
@indrekots
indrekots / mock.java
Created December 24, 2013 17:12
Creating a mock class with Mockito
UserDao userDao = Mockito.mock(UserDao.class);
@indrekots
indrekots / whenThenReturn.java
Created December 30, 2013 21:54
Example on how to stub methods with Mockito
Mockito.when(userDao.getUserById(1L)).thenReturn(new User("Mario"));
@indrekots
indrekots / mockitoWhenThenThrow.java
Created January 4, 2014 09:04
Subbing a behavior which throws an exception in Mockito
Mockito.when(userDao.getUserById(111)).thenThrow(new NoResultException());