Posts Tagged ‘Zend Framework’

h1

SimplePie & ZendFramework

April 21, 2009

I\’ve been working on my old site the past couple of days and needed to integrate a blog aggregator for my wordpress blog.

Instead of doing it all from scratch & reinventing the wheel, I decided to integrate SimplePie into my Zend Framework project.

Listed below are the steps I needed to get  SimplePie into Zend Framework.

  • Download SimplePie
  • Rename simplepie.inc to SimplePie.php & copy to the library directory of your ZF project.
  • If you want dates you will also need idn/idna_convert.class.php
  • Rename idna_convert.class.php to convert.php & create a directory called \’idna\’ within the library directory
  • Move the newly renamed convert.php & npdata.ser to library/idna
  • Now we are ready to utilise SimplePie within our project.

Below are excerpts from my project, hopefully it will help illustrate how to utilise SimplePie once you have made the necessary changes.


class BlogController extends BaseController {

	function init() {
		$feed = new SimplePie(\'https://baphled.wordpress.com/feed\');
		$feed->init();
		$this->view->title = $feed->get_title();
		$this->view->items = $feed->get_items();
		parent::init();
	}
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
	}

}

Above we instantiate SimplePie with the URL to our RSS feed, we then initialise our feed & retrieve it\’s title & items, assigning the variables to the view.

The next segment of code is for the index.phtml and basically populates our content with our aggregated blog feed.

foreach($this->items as $item): ?>
	<div class=\"chunk\" style=\"padding:0 15px;\">
		<h4><a href=\"{$item->get_permalink()}\" target=\"_blank\"><?php echo $item->get_title(); ?></a></h4>
		<?php echo $item->get_description(); ?>
		<p class=\"footnote favicons\" align=\"center\">
			<a href=\"<?php echo $item->add_to_blinklist(); ?>\" title=\"Add post to Blinklist\"><img src=\"/images/favicons/blinklist.png\" alt=\"Blinklist\" /></a>
			<a href=\"<?php echo $item->add_to_blogmarks(); ?>\" title=\"Add post to Blogmarks\"><img src=\"/images/favicons/blogmarks.png\" alt=\"Blogmarks\" /></a>
			<a href=\"<?php echo $item->add_to_delicious(); ?>\" title=\"Add post to del.icio.us\"><img src=\"/images/favicons/delicious.png\" alt=\"del.icio.us\" /></a>
			<a href=\"<?php echo $item->add_to_digg(); ?>\" title=\"Digg this!\"><img src=\"/images/favicons/digg.png\" alt=\"Digg\" /></a>
			<a href=\"<?php echo $item->add_to_magnolia(); ?>\" title=\"Add post to Ma.gnolia\"><img src=\"/images/favicons/magnolia.png\" alt=\"Ma.gnolia\" /></a>
			<a href=\"<?php echo $item->add_to_myweb20(); ?>\" title=\"Add post to My Web 2.0\"><img src=\"/images/favicons/myweb2.png\" alt=\"My Web 2.0\" /></a>
			<a href=\"<?php echo $item->add_to_newsvine(); ?>\" title=\"Add post to Newsvine\"><img src=\"/images/favicons/newsvine.png\" alt=\"Newsvine\" /></a>
			<a href=\"<?php echo $item->add_to_reddit(); ?>\" title=\"Add post to Reddit\"><img src=\"/images/favicons/reddit.png\" alt=\"Reddit\" /></a>
			<a href=\"<?php echo $item->add_to_segnalo(); ?>\" title=\"Add post to Segnalo\"><img src=\"/images/favicons/segnalo.png\" alt=\"Segnalo\" /></a>
			<a href=\"<?php echo $item->add_to_simpy(); ?>\" title=\"Add post to Simpy\"><img src=\"/images/favicons/simpy.png\" alt=\"Simpy\" /></a>
			<a href=\"<?php echo $item->add_to_spurl(); ?>\" title=\"Add post to Spurl\"><img src=\"/images/favicons/spurl.png\" alt=\"Spurl\" /></a>
			<a href=\"<?php echo $item->add_to_wists(); ?>\" title=\"Add post to Wists\"><img src=\"/images/favicons/wists.png\" alt=\"Wists\" /></a>
			<a href=\"<?php echo $item->search_technorati(); ?>\" title=\"Who\'s linking to this post?\"><img src=\"/images/favicons/technorati.png\" alt=\"Technorati\" /></a>
		</p>
	</div>
<?php endforeach; ?>
h1

Zend_PHPUnit_Fixtures uploaded to GitHub

December 4, 2008

Well I’ve been working on this project (Zend PHPUnit Fixtures) along with a few collegues over the past few months, It was my intension to submit it to Zend some point in the new year but thought I’d put it out in the wild for others to pick at.

Well I use TDD (PHPUnit is my friend) on a daily basis within ZendFramework and soon found it cumbersome to create test data (fixtures) ending up in huge test cases with more test data setup than actual assertions, this matched up with the fact that I hate integrating DB into my tests (mainly because the tables would still contain old test data & fail depending on whether the data was added in previous tests or not) So I decided to do some digging, the best solution seemed to be to create a fixture handling system that plugs into ZendFramework, leaving myself and others with more time actually testing and less time building up test data and removing fixtures from a database (which can be near impossible when it comes to automated testing).

With this realisation I decided to create my own which I’ve reversed engineered from CakePHP. When I have the time (hopefully over the holidays) I’ll go into how the mini framework can be used. For now I’ll just describe the features or each class and what they are for:-

PHPUnit_Fixtures

Basic fixture handler, used for creating test data that does not interact with a DB. With this object we are able to create basic fixtures that we can use for dummy data with our test cases. Each piece of test data can have an alias (‘ALIAS’) with the aliases name as the value, doing so will allow us to use the PHPUnit_Fixtures::find($aliasName) which will retrieve the desired fixture.

PHPUnit_Fixtures_DB

Has the same functionality as PHPUnit_Fixtures but used specifically for DB centric tests, DB test data will be added to our ‘_test’ DB, and cleaned up (truncated) on each test case, to make sure that we have the expected data.

PHPUnit_Fixtures_DynamicDB

Has the same functionality as PHPUnit_Fixture_DB, with the added functionality of being able to create tables setup my MySQL Workbench. With an child object of this class we are able to specify retrieving all schema or a specific on (denoted by the schema table name).

DevelopmentHandler

Used to handle our development environments, there are times when we want to quickly place test data on our staging DB for functionality testing and the such like, this class along with one of our PHPUnit_Fixtures, will easily allow us to populate this environment with the data we have been using for our unit tests, making it quicker to migrate test data from one place to another.

You can find the project at GitHub, If anyones interested in adding to this project or have any comments/questions drop me a line.

h1

Installing ZendStudio 6.1

October 20, 2008

Okay, I’ve done this so many times & helped a few people do the same that I thought It would be a good idea to actually document the process. I’ll explain the basic steps to getting ZendStudio working with PHP5.2.6 & PHPUnit3, this setup will allow you to use the same library files as the actual system instead of the environment prepacked with ZS6.1 (I prefer this way as running tests in ZS6.1 should produce the same results when run via CLI.

Needed:
PHP5.2.6
ZF latest version
ZendStudio for Eclipse 6.1
PEAR

Make sure that php is atleast at version 5.2 (php -v will tell you the version), update if needed. Download Zend Framework and place in your php include path (typically /usr/share/php or /usr/share/pear).

If pear is not installed we’ll need install it using the following for Debian based systems (remember you’ll need to be root to install via apt or yum).
apt-get install php-pear
and
yum install php-pear
for RHEL based systems.

cd /opt &&
wget http://framework.zend.com/releases/ZendFramework-1.7.0PR/ZendFramework-1.7.0PR.zip &&
unzip ZendFramework-1.7.0PR.zip &&
cd ZendFramework-1.7.0PR/library/ &&
mv Zend INCLUDE_PATH

Now we have ZF within our include path we need to setup PHPUnit & ZendStudio.
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit

We need to download ZendStudio from here & running the file
./ZendStudioForEclipse-6_1_0.bin Follow the instructions & wait for the installation to complete.

Now we’ll need to customise ZS so that it will work with using the systems PHP & PHPUnit instead of the ones packed with ZS.

We’ll need to setup ZendDebugger to work with our systems php.ini file, so we will need to copy ZendDebugger from ZS and place in with the other modules.
cp /PATH/TO/ZEND/plugins/org.zend.php.debug.debugger.linux.x86_5.2.14.v20080602/resources/php5/ZendDebugger.so /usr/lib/php5/

Here we need to add the below text into our php.ini file, ideally at the bottom, so it is easy to find.
[Zend]
zend_extension=/usr/lib/php5/ZendDebugger.so
zend_debugger.allow_hosts=127.0.0.1
zend_debugger.expose_remotely=always
zend_debugger.connector_port=10000

Once installed and started, select Window, Preferences & you’ll be given a window simular to below.

Click Add, which will bring up the dialog box below.

Enter the following, the path to the systems php executable & your php.ini file as entered in the above screenshot and click Finish.

The dialog box will close and leave you with Figure 1.1, select the newly added settings and click Default. We have now setup ZS to work with our systems PHP version instead of the one packed with ZS.

We now need to add a our PHP include path to ZS so that we have all our library files available for ZS.

Click New, which will display the below dialog box, this is where we need to set our current PHP path, the screenshot below displays an example.

Once the include path has been added we click OK and OK again, now when ever we create a new project, we will just remove the predefined paths and just include our one.

Well that’s it, now we should be able to run tests within ZendStudio & the shell, knowing that our results come from the same environment..