Testing in isolation with Symfony2 and WebTestCase

It’s extremely important to have same state of the System Under Test. In most of the cases it will be possible by having same contents in a database for every test. I’ve decribed how to achieve it in Fully isolated tests in Symfony2 blog post about two years ago (btw. it’s most popular post on this blog). It was the time, when PHP’s Traits weren’t that popular.

Read more

Injecting repositories to service in Symfony2

It is generally a good idea to wrap business logic into services. Often, such services methods uses doctrine’s repositories to operate on data storage. Injecting whole EntityManager service is very popular approach, but it isn’t the most elegant way I could think of. EntityManager works only as a factory in that case and could lead to usage of other repositories, which might end up with too many responsibilities of given service.
The better way, is to inject single repositories, using factory-service mechanizm, provided by Dependency Injection Container.

Read more

Export colored Behat scenarios to PDF

Everyone falls in love with Behat. It’s powerfull tool for testing business requirements in PHP. Behat scenarios, written in cross-platform Gherkin language, are readable for developers, easy to understand and verify for business people and executable by machine, which goes through an application to prove that it works as expected.

Behat scenarios are one of the best ways to describe system. UML Use Cases or tons of pages in SRS documents are fine, but hard to understand from the begining, and even harder to maintain in the future. Behat eases this process and also gives opportunity to automate requirements verification.

Read more

Let’s meet at PHPCon 2012Spotkajmy się na PHPCon 2012

During upcoming edition of PHPCon 2012 in Kielce I’ll give a talk “Symfony2 w chmurze” (Symfony2 in the cloud). I’ll describe advantages of cloud infrastructure purposed for web applications, some use cases of cloud deployments and things which developers need to keep in mind, to get Symfony2 application work properly in such environment.

More informations are available in PHPCon agenda:http://phpcon.pl/2012/pl/agenda

See you there :-)Podczas tegorocznej konferencji PHPCon 2012 w Kielcach (28-30 września) będę miał przyjemność poprowadzić prelekcję “Symfony2 w chmurze”. Będę mówił o zaletach korzystania z chmury jako infrastruktury serwerowej pod aplikacje webowe, przykładowych przypadkach użycia oraz zabiegach, o których należy pamiętać, aby aplikacja w napisana w frameworku Symfony2 działała poprawnie w takim środowisku.

Więcej informacji w agendzie PHPCon: http://phpcon.pl/2012/pl/agenda

Do zobaczenia :-)

Read more

Why Mockery is better than PHPUnit Mock Builder and how to integrate it with Symfony2

Recently I did a lot of Test Driven Development on my Symfony2 bundle. I used PHPUnit’s built-in mocks and stubs for many projects, so I took it again. But while I was working on mocking Symfony2 core objects I found those mocks very uncomfortable in use. I tried Mockery and it saved my day. Let’s see how to get it working with Symfony2 and how it kicks ass!

Read more

Use Proxy-Object in Symfony2 applictions to test non-public methods

Generally, it’s not a good idea to unit test protected or private methods, but in some cases it could be useful. Of course we don’t want to change our class contract, and expose those methods as a public ones, just becasue we want to test them with PHPUnit. This case can be solved with Proxy-Object library. It provides easy-to-use way to get protected classes to the surface. More about that is here http://blog.bastian-feder.de/blog/029_proxyObject.html. Here I’ll show how to integrate proxy object into your Symfony2 application:

Read more

How to add a custom class to form field in Symfony2

Today I needed to add a custom class to textarea field, to achieve TinyMCE field rendering (with help of http://symfony2bundles.org/stfalcon/TinymceBundle). It wasn’t such straightforward like I thought… I tried:

But it threw exception, that attribute “class” is undefined, so I need to solve it in other way. Thank god I use Twig, so I tried form theming (in template with form). Only thing you need to do is to find out html ID of the textarea field (in my case: wowo_bundle_newsletterbundle_newslettertype_mailing_body). Then you need to add a “_” on the front and “_widget” on the end and class=”tinymce” is there for you.

The solution is simple and powerful, Symfony2 has proven its quality again :-)

UPDATE 19.10.2011
As Florian and Stloyd mentioned in comments, setting custom class can be done in elegant way, which ain’t included in the documentation yet.

UPDATE 29.10.2011

After my contribution, “attr” element is now documented in official Symfony2 docs http://symfony.com/doc/current/reference/forms/types/field.html

Read more

Loosening dependencies with closures in PHP

Today I ran into a little issue: how to pass generic logger object to method? I wanted to get some verbose output from method, which I call from Command, but onc time it should log with Symfony2 OutputInterface and other time it should use monolog logger. Of course I can make some wrapper class for both of them, but it would be kind of an overkill. The Closure from PHP 5.3 came with solution. In calling method I created closure like this:

On the second hand I’ve got:

As you can see I don’t need to care about logging – just call the closure with message and it will log it properly, depending on context.

Read more

Moja prezentacja o Symfony2 i dedykowanym oprogramowaniu z InternetBeta 2011

Poniżej slajdy z mojej prezentacji, którą wygłosiłem na InternetBeta 2011 w Rzeszowie. Zapraszam do zapoznania się z slajdami.

Read more

Prezentacja o Symfony2 i oprogramowaniu dedykowanym na InternetBeta 2011 w Rzeszowie

W czwartek 15 września 2011 o 14:30 będę miał przyjemność prowadzić prelekcję na Sesji Technologicznej InternetBeta 2011 w Rzeszowie. Mój temat to Łebski Development czyli kiedy i dlaczego tworzyć oprogramowanie pod klucz i dlaczego framework Symfony2 pasuje tu jak ulał? A poniżej krótka agenda:

  • - oprogramowanie dedykowane vs. produkty Open Source gotowe do użycia – w którym momencie te drugie przestają być wystarczające,
  • - jaką wartością jest indywidualne podejście do zagadnienia i gdzie każdy z udziałowców projektu otrzymuje największe korzyści,
  • - po co komu framework, skoro można wszystko samemu napisać najlepiej?
  • - Symfony2, jego historia, możliwości i usytuowanie na rynku,
  • - przykłady z życia codziennego, jak PHP i Symfony2 zwinnie daje radę w przeróżnych dziedzinach software developmentu.

Wszystkich zainteresowanych tematem serdecznie zapraszam :-)

 

Read more
starsze
Back to top