---
layout: post
title: Put Your Behaviors On Steroids
published: true
---
<p>Propel is bundled with a lot of <a href="http://www.propelorm.org/documentation/#behaviors_reference">great behaviors</a>. All of them are real behaviors, not just extensions, that's why it's really powerful. You can customize every generated class without any effort thanks to hooks, and filters.</p>
<p>To write a behavior is easy, you just have to read the <a href="http://www.propelorm.org/cookbook/writing-behavior.html">dedicated documentation page</a>, and you'll be ready to write awesome behaviors. Don't forget to look at <a href="http://www.propelorm.org/cookbook/user-contributed-behaviors.html">user contributed behaviors</a>&nbsp;before to start, maybe someone already wrote what you need.</p>
<p>A behavior adds logic to your model layer so it must be unit tested. Most of the time, you will have to rely on the <a href="https://github.com/propelorm/Propel/blob/master/generator/lib/util/PropelQuickBuilder.php">PropelQuickBuilder</a> to setup your test suite. This builder will build classes for a given XML schema. The code below shows an example of a test class:</p>
<p><!--more--></p>
<p><script src="https://gist.github.com/2469706.js"></script></p>
<p>The <em>MyObject</em> class is created in memory, and you can use it as usual in your code. The next step is to make your behavior easy to install. The best option is to rely on <a href="http://getcomposer.org/">Composer</a>:</p>
<p><script src="https://gist.github.com/2469507.js?file=composer.json"></script></p>
<p>The convention here is to prefix your package name with <em>propel-</em>, and to suffix it with <em>-behavior</em>. Please, follow this convention. Don't forget to add Propel as requirement, and you will be ready to add it on <a href="http://packagist.org/">Packagist</a>.</p>
<p>Now, what about using&nbsp;<a href="http://travis-ci.org/">travis-ci</a>&nbsp;to automatically run your behavior's test suite? <a href="https://github.com/Carpe-Hora/AuditableBehavior">Auditable</a>,&nbsp;<a href="https://github.com/willdurand/GeocodableBehavior">Geocodable</a>, or&nbsp;<a href="https://github.com/willdurand/TypehintableBehavior">Typehintable</a>&nbsp;are already on&nbsp;<a href="http://travis-ci.org/">travis-ci</a>, and use the following configuration:</p>
<p><script src="https://gist.github.com/2469507.js?file=.travis.yml"></script></p>
<p><script src="https://gist.github.com/2469507.js?file=bootstrap.php"></script></p>
<p>That's all! You know everything to build great behaviors.</p>
