Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Sunday, February 5, 2012

working with DateTime instances in Doctrine 2

DateTime changes are detected by Reference

When calling EntityManager#flush() Doctrine computes the changesets of all the currently managed entities and saves the differences to the database. In case of object properties (@Column(type=”datetime”) or @Column(type=”object”)) these comparisons are always made BY REFERENCE. That means the following change will NOT be saved into the database:
<?php
/** @Entity */
class Article
{
    /** @Column(type="datetime") */
    private $updated;

    public function setUpdated()
    {
        // will NOT be saved in the database
        $this->updated->modify("now");
    }
}
The way to go would be:
<?php
class Article
{
    public function setUpdated()
    {
        // WILL be saved in the database
        $this->updated = new \DateTime("now");
    }
}​

Refere​nce:
http://www.doctrine-project.org/docs/orm/2.0/en/cookbook/working-with-datetime.html

Problem running Zend commands inside NetBeans (solved)

When trying to run zf commands inside Netbeans
it didn't work until I did the following:
    1. ​Using cmd I created the .zf.ini file using the script​ "zf --setup fonfig-file"
      1. .zf.ini is in your user directory like in windows: "C:\Users\abdelhady_mohammed"
    1. Then I opened netbeans and from tools>Options>php>Zend, then choosed "Register Provider"
    2. Right click the project Zend>run command and choose "Refresh Commands"
And here we go, every thing is Ok inside Netbeans

Then I tried to run zf commands again on windows command line:
And here comes the bug, zf commands is no longer runnable on windows command line and here is the full bug report on Netbeans site:

Solution:
get the "NetBeansCommandsProvider.php" located in "D:\Boston_Dev_Env\NetBeans\php\zend"
and copy it to the Zend Library folder "D:\Boston_Dev_Env\server\ZendFramework-1.11.7\library"

and every thing will be fine then

Additional reference:
http://www.kilinjal.com/blog/how-configure-zend-tool-netbeans?page=show

Installing PhpUnit manually for PEARLESS people ( on windows)

PHPUnit

The first thing is to download and extract PHPUnit, download the file, unzip it and place the resulting folder in
1 C:\wamp\bin\php\php5.2.9-2\
(I renamed the folder from PHPUnit-3.5.4 to phpunit but its up to you. You can also put the folder anywhere you want, so long as you amend the include path instruction below).

PHP.ini

With the PHPUnit files extracted, we need to alter our php.ini file to have an include path of our PHPUnit directory, add the following line to the appropriate section of the php.ini file.
1 include_path = "C:\wamp\bin\php\php5.2.9-2\phpunit"

Dependancies

Because I didn't/couldn't/wouldn't install this through PEAR, there were quite alot of dependancies missing, which was frustrating considering the manual installation instructions didn't mention this. I also found, that these dependancies had to be extracted to the (root) phpunit folder, and not the PHPUnit folder within there (which is where I'd initially put them - to a further series of errors!). Download the following dependancies, and extract them to the root phpunit folder (i.e. C:\wamp\bin\php\php5.2.9-2\phpunit).
  • PHP/CodeCoverage (copy the PHP folder and its contents)
  • PHP/Timer (copy the PHP folder and its contents (don't override the PHP folder from the previous dependancy))
  • PHP/TokenStream (copy the PHP folder and its contents (don't override the PHP folder from the previous dependancies))
  • Text/Template (copy the Text folder and its contents)
  • File/Iterator (copy the File folder and its contents)

The bat (cave) file

Since we are running on Windows, to run PHPUnit, we can't simply rename phpunit.php to phpunit and run it (as per the instructions), we instead run the phpunit.bat file. The bat file in turn runs the PHP executable, and opens the phpunit.php file with it.
Open the phpunit.bat file, and replace its contents with the following (replacing paths to php.exe and phpunit.php with your own systems paths).
1 C:\wamp\bin\php\php5.2.9-2\php.exe -d safe_mode=Off "C:\wamp\bin\php\php5.2.9-2\phpunit\phpunit.php" %*

phpunit.php

Within the phpunit.php file you need to replace @php_bim@ with the path to your php directory (as per the documentation)
1 C:\wamp\bin\php\php5.2.9-2

Running PHPUnit

Now simply open the command prompt, browse to your phpunit folder, and run phpunit followed by the file path of your tests.

Reference:
http://www.michaelpeacock.co.uk/blog/entry/phpunit-on-wamp​