Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Archive for Czerwiec, 2013

Anna Filina: How to Motivate Your Developers

Anna Filina: How to Motivate Your Developers

Anna Filina has a quick new post to her site today with some helpful tips on how to motivate your developers (and coworkers) to make for the best end result.

When developers are not motivated, progress is slow and quality is low. This ultimately affects company revenues and can lead to reduced opportunities for all employees. Motivation leads in the opposite direction: wealth and happiness. The first thing to understand about motivation is that it’s internal. We can’t force someone to become motivated, but we can still have a strong influence. Here are my top three picks to increase motivation from my presentation at IPC 2013 in Berlin.

Her top three are:

  • Setting goals for the group and a purpose for making it good
  • Focus on the “small wins” sometimes to keep motivation high
  • Let developers use their full range of talents, don’t force them into one niche

Link: http://annafilina.com/blog/motivate-developers
Source: http://www.phpdeveloper.org/news/19777

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

The PHP.cc: Urban Legends and Error Handling

The PHP.cc: Urban Legends and Error Handling

In this new post to the PHP.cc blog, Stefan Priebsch looks at the relationship between urban legends and error handing in PHP.

Ending up in such a situation [as the tourists in the urban legend] is not the fault of the underpass: the error, made somewhere upstream, merely shows up right when approaching the underpass, and is usually difficult (or at least tedious) to handle. PHP as a programming language, just like any dynamic language, may at first appear to not need overly strict validations of data. Validation of data, however, is directly related to error handling: If data is invalid, this should be an error or an exception (if you write OOP code, which you should be doing). This error needs to be handled somewhere.

He talks about how things like field and value validation can help prevent errors further down the road. He mentions the split between application and domain logic and suggests that it’s the role of the app logic to prevent bad data from making it thorough to the domain.

In software development, it is crucial that you handle any errors as soon as they occur. This requires you to actually realize that an error has occurred.

Link: http://thephp.cc/viewpoints/blog/2013/06/urban-legends-and-error-handling
Source: http://www.phpdeveloper.org/news/19776

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Quick Introduction To BDD Testing With Behat

Quick Introduction To BDD Testing With Behat

Behat is a PHP framework for BDD testing. It us very similar to Cucumber (RoR) or Behave (Django), it uses Gherkin language to define features and scenarions. These are then executed by Behat, which uses one or several drivers. In this short example I will show you how to use two drivers:

  • Goutte (simple HTTP based headless browser)
  • Selenium 2 (full browser emulator with JS support)

First, let’s use Composer to install Behat and the drivers:

{
    "name": "foo-bar",
    "description": "Foo Bar",
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3",
    },
    "require-dev": {
        "behat/behat": "dev-develop#1f1bead31e96da5e30fd5d499d5cf66d29b68cf6",
        "behat/mink": "v1.4.3",
        "behat/mink-extension": "dev-master#ef2c8639ebc254f0ff6e555b7834700caf5db9c4",
        "behat/mink-goutte-driver": "dev-master#v1.0.8",
        "behat/mink-selenium2-driver": "v1.0.6",
    }
}

Install the dependencies defined in composer.json file (above):

php composer.phar install --dev

Make sure you have Firefox 21 installed as that’s what we will be using for Selenium 2 tests. Also important, make sure you have Selenium 2 server installed and running. I have written a post explaining how to install Selenium 2 on Mac OS as a service.

This is an example behat.yml file I’m using in one of projects I work on:

default:
  paths:
    features: tests/functional/features
    bootstrap: tests/functional/features/bootstrap
  extensions:
    Behat\MinkExtension\Extension:
      base_url: http://virtualhost.local
      goutte: ~
      default_session: goutte
      javascript_session: selenium2
      selenium2:
        browser: firefox
        capabilities: { "browserName": "firefox", "browser": "firefox", "version": "21"}
        wd_host: http://127.0.0.1:4443/wd/hub

Then you can run the tests like this:

vendor/bin/behat --ansi

All tests with @javascript tag will use Selenium 2 driver (so a new Firefox window will pop up and your tests will run inside it), tests without @javascript tag will run using the headless Goutte driver.

You can exclude Selenium 2 tests like this (for example you might not have an external Selenium 2 server for Jenkins so you might want to run Selenium tests only locally and run only tests without @javascript tag on Jenkins as a part of the build process):

vendor/bin/behat --ansi --tags=~@javascript

Source: http://blog.richardknop.com/2013/06/quick-introduction-to-bdd-testing-with-behat/

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Installing Selenium 2 On Mac OS As Service

Installing Selenium 2 On Mac OS As Service

Selenium 2 is a powerful browser emulator which enables you to automate frontend testing (especially JavaScript heavy pages). It can be used with Behat as well for BDD testing.

I prefer using Goutte headless driver to test basic functionality and flow of the application but sometimes there are critical parts of the app that rely heavily on client side technologies like JavaScript. Only way to test to those is to use a browser emulator (Selenium 2, Sahi etc). Enough talking, here is how I installed Selenium 2 server on Mac OS as a service:

wget https://selenium.googlecode.com/files/selenium-server-standalone-2.33.0.jar

sudo mkdir /usr/lib/selenium

sudo mv selenium-server-standalone-2.33.0.jar /usr/lib/selenium

sudo mkdir /var/log/selenium

sudo chmod -R a+w /var/log/selenium

Then you need to create a new file:

sudo nano ~/Library/LaunchAgents/org.nhabit.Selenium.plist

With contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>org.nhabit.Selenium</string>
        <key>OnDemand</key>
        <true/>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/java</string>
                <string>-jar</string>
                <string>/usr/lib/selenium/selenium-server-standalone-2.33.0.jar</string>
                <string>-port</string>
                <string>4443</string>
        </array>
        <key>ServiceDescription</key>
        <string>Selenium Server</string>
        <key>StandardErrorPath</key>
        <string>/var/log/selenium/selenium-error.log</string>
        <key>StandardOutPath</key>
        <string>/var/log/selenium/selenium-output.log</string>
</dict>
</plist>

Load the service:

launchctl load ~/Library/LaunchAgents/org.nhabit.Selenium.plist
launchctl start org.nhabit.Selenium

You can also check it’s running:

ps aux | grep selenium

richardknop    19880   0.0  0.5  2859020  76648   ??  S     2:09pm   0:07.05 /usr/bin/java -jar /usr/lib/selenium/selenium-server-standalone-2.33.0.jar -port 4443
richardknop    20852   0.0  0.0  2432768    596 s001  R+    3:17pm   0:00.00 grep selenium

And error logs, just in case you need them:

tail -f /var/log/selenium/selenium-error.log

Source: http://blog.richardknop.com/2013/06/installing-selenium-2-on-mac-os-as-service/

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Are Backbone Models Singletons?

Are Backbone Models Singletons?

I have been using Backbone (plus couple of other JavaScript libraries) for my last project. One of the first problems I encountered was this simple code:

var Foo = Backbone.Model.extend({
    defaults: {
        bars: []
    }
});

var foo = new Foo();
foo.get("bars").push("a");
foo.get("bars").push("b");
console.log(foo.get("bars"));

var foo = new Foo();
foo.get("bars").push("c");
foo.get("bars").push("d");
console.log(foo.get("bars"));

A simple model with array as a property, seems pretty straightforward. But when I created two instances of the model, this was logged in the console:

["a", "b", "c", "d"]
["a", "b", "c", "d"]

JSFiddle

Well, the problem was that the property declared in defaults is a global one. In order to avoid this rookie mistake, init all arrays or dictionaries in initialize method:

var Foo = Backbone.Model.extend({
    initialize: function() {
        this.set("bars", []);
    }
});

Here is my related StackOverflow question: Are Backbone Models Singletons?

Source: http://blog.richardknop.com/2013/06/are-backbone-models-singletons/

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Community News: Packagist Latest Releases for 06.23.2013

Community News: Packagist Latest Releases for 06.23.2013Recent releases from the Packagist:

Source: http://www.phpdeveloper.org/news/19754

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Community News: Packagist Latest Releases for 06.22.2013

Community News: Packagist Latest Releases for 06.22.2013Recent releases from the Packagist:

Source: http://www.phpdeveloper.org/news/19753

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Evert Pot: PHP 5.5.0 released!

Evert Pot: PHP 5.5.0 released!

With PHP 5.5 just released you might be wondering what improvements came with it (and the one-line descriptions on PHP.net aren’t enough). Well, Evert Pot as put together a post talking about some of these features and has included code samples to show them at work.

PHP 5.5 has been released! Quite exciting stuff, and pretty great to see the pace of new releases. Props to the dev team! Hopefully distros pick this version up quickly as well, so we can start making use of these fancy new features.

His list (and sample code) shows off:

  • Generators
  • Immutable DateTime object
  • Lists in foreach
  • Finally keyword
  • Class name resolution
  • Opcode cache is now integrated and enabled by default in PHP
  • Constant dereferencing

You can go download this release right now and try it all out for yourself too!

Link: http://evertpot.com/php-55-released
Source: http://www.phpdeveloper.org/news/19752

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

VG Tech Blog: Selenium Tests

VG Tech Blog: Selenium Tests

On the VG Tech blog today there’s a new post introducing Selenium testing to those that might not have heard of it before for functional testing. It’s a powerful tool that can even be used from inside PHPUnit tests to automate evaluation of your frontend application.

When we develop code at VG we have started to use Selenium tests for continuous integration. This allows us to easy write tests that programmatically checks that last commit didn’t break anything.

He describes some of the types of tests Selenium can do and mentions the IDE that can hook into Firefox and record your actions and translate them into tests. This includes the ability to export them to PHPUnit tests (sample code provided) that extend the “PHPUnit_Extensions_SeleniumTestCase.” An example screenshot of what the IDE running looks like is also included.

Link: http://tech.vg.no/2013/06/14/selenium-tests
Source: http://www.phpdeveloper.org/news/19751

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

VG Tech Blog: Selenium Tests

VG Tech Blog: Selenium Tests

On the VG Tech blog today there’s a new post introducing Selenium testing to those that might not have heard of it before for functional testing. It’s a powerful tool that can even be used from inside PHPUnit tests to automate evaluation of your frontend application.

When we develop code at VG we have started to use Selenium tests for continuous integration. This allows us to easy write tests that programmatically checks that last commit didn’t break anything.

He describes some of the types of tests Selenium can do and mentions the IDE that can hook into Firefox and record your actions and translate them into tests. This includes the ability to export them to PHPUnit tests (sample code provided) that extend the “PHPUnit_Extensions_SeleniumTestCase.” An example screenshot of what the IDE running looks like is also included.

Link: http://tech.vg.no/2013/06/14/selenium-tests
Source: http://www.phpdeveloper.org/news/19751

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>