Skip to content

Instantly share code, notes, and snippets.

View alnutile's full-sized avatar

Alfred Nutile alnutile

View GitHub Profile
@alnutile
alnutile / behat.inc.php
Created January 11, 2014 01:20
Switch to popup
/**
* @hidden
*
* @Then /^I switch to popup by clicking "([^"]*)"$/
*/
public function iSwitchToPopupByClicking($arg1) {
$originalWindowName = $this->getMainContext()->getSession()->getWindowName();
$this->setMainWindow();
$this->getMainContext()->getSession()->getPage()->clickLink("$arg1"); //Pressing the withdraw button
@alnutile
alnutile / behat.inc.php
Created January 11, 2014 01:27
Test Height
/**
* See if the element (name|label|id) is greater than the % of the window
*
* @Then /^the element "([^"]*)" should be "([^"]*)" percent or greater than the window$/
*/
public function theElementShouldBePercentOrGreaterThanTheWindow($arg1, $arg2)
{
//@todo
$javascript_check = <<<HEREDOC
if(!jQuery('$arg1').length) { return "FAILED"; }
@alnutile
alnutile / behat.yml
Created January 13, 2014 15:41
example for behat_editor tests
default:
paths: { features: features }
extensions: { Behat\MinkExtension\Extension: { default_session: selenium2, goutte: null, selenium2: null, base_url: 'http://behatpfizer.local/', browser_name: safari, javascript_session: selenium2 }, Drupal\DrupalExtension\Extension: { blackbox: null, api_driver: drush, drush: { alias: digitalocean.behateditorp_staging }, subcontexts: { paths: [/Users/test/Drupal/behat_vagrant/behat_pfiser/assets/example/current/sites/all/modules] } } }
@alnutile
alnutile / model.php
Created February 2, 2014 16:02
Static update on model
/**
* Update a model instance in the database.
*
* @param mixed $id
* @param array $attributes
* @return int
*/
public static function update($id, $attributes)
{
$model = new static(array(), true);
@alnutile
alnutile / ProjectsController.php
Created February 2, 2014 16:53
Bad example of updating relations
//@TODO start using the BaseModel helper
$validate = Validator::make(Input::all(), Project::$rules);
$project = Project::find($id);
if($validate->passes()) {
$inputs = Input::all();
$project->name = $inputs['name'];
$project->description = $inputs['description'];
$project->active = (isset($inputs['active'])) ? $inputs['active'] : 0;
$project->giturl = $inputs['giturl'];
$project->accountingurl = $inputs['accountingurl'];
@alnutile
alnutile / ProjectsController.php
Created February 2, 2014 16:58
Example of Store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//@TODO start using the BaseModel helper
$validate = Validator::make(Input::all(), Project::$rules);
@alnutile
alnutile / guard_all_files
Last active August 29, 2015 13:56
Watch all files for change in the laravel app folder then find the matching test in app/tests/ eg app/controllers/User.php will trigger app/testes/controllers/UserTest.php
guard 'phpunit2', :tests_path => 'app/tests', :cli => '--colors' do
watch(%r{^.+Test.php$})
watch(%r{app/(.+)/(.+).php}) { |m| "tests/#{m[1]}/#{m[2]}Test.php" }
end
@alnutile
alnutile / services.php
Created February 6, 2014 13:28
Drupal Services and instantiating a class
/**
* Implements hook_services_resources()
*/
function behat_editor_tokenizer_services_resources() {
return array(
'tokenizer' => array(
'retrieve' => array(
'help' => 'Retrieve a token record',
'callback' => 'behat_editor_tokenizer_callback',
'access callback' => 'behat_editor_tokenizer_access',
@alnutile
alnutile / Custom Facade
Created February 10, 2014 20:18
Custom Facade being called but not getting args
Route::get('issues', function(){
return GitHubService::getIssues('alnutile', 'fis2');
});
@alnutile
alnutile / GitHubService.php
Created February 10, 2014 20:56
note2self setting per page via the api call using the https://github.com/KnpLabs/php-github-api
public function getAllProjects($repoOwner)
{
try {
$results = $this->client->api('user')->setPerpage('200')->repositories($repoOwner);
}
catch(\Exception $e) {
return $e->getMessage();
}