I am new in PrestaShop and I need to create custom module, with XML files parsing and database operations. I would like to create unit test for this module, because I don't want to test it 'by hand'. Could you provide me any advices, methods or articles on the Web about the patterns how to do it well? I can't find good tutorial using web search engine.
I did write a blog post about testing prestashop with Mink and Behat (Cucumber equivalent) which you can read here - http://xavierriley.co.uk/blog/2012/10/12/test-driving-prestashop-with-behat/
There's also this pull request on Github for adding unit tests to the project - https://github.com/PrestaShop/PrestaShop/pull/70
The tooling for testing things like this in PHP doesn't seem to be as mature as the Ruby/Java equivalents so don't get your hopes up, but that should be a start.
Related
I am developing project witch has console logic, restfull API, admin and client websites.
I have started building all of them in single ZF2 application. I am using Application module for client website and console logic, API module for API and Admin module for admin website. And then I have started writing unit tests I realized that then I am calling some part of my code every module is being loaded (for example when I am calling console script witch only works with emails via IMAP my api documentation tool swagger is printing warnings about no server name).
I think this should decrease app performance and changing one part can break another. And also all parts are really diferent(Console, Restfull, and html output. different plugins, vendors ect.).
And now I think how can I solve this problem. I would like to keep the structure:http://mysite/api for API, http://mysite/admin for admin, http://mysite/ for client site and php index.php action for console scripts.
How I should solve this problem? Should I split all those parts to separate ZF2 applications, or should I use same project but, some different autoloader. Or maybe there is some other good practices?
Don't rearchitect your whole application to fix a performance problem you think might exist. The module bootstrap overhead for ZF2 is quite low. If your modules really have no dependencies on each other at all, try benchmarking your application as a baseline, then try disabling one module to see what difference it makes. If it doesn't make much difference, I'd keep it as it is.
I have experience with Joomla and have modified and wrote some simple Joomla extensions. I don't have experience using one of the popular PHP frameworks (such as CakePHP), but I was thinking about using the Joomla framework because I'm familiar with Joomla. How would I use the Joomla framework for a software project instead of using regular Joomla and writing the extensions needed for it to extend it's capabilities? Thanks!
The basic idea is that you:
Get a copy of either the whole framework or just the packages you need+dependencies (from github or composer) or use the older copy that is shipped with the CMS,
Bootstrap your application (JApplicationWeb or JApplicationCli).
Write your code using the MVC structure provided.
The big difference with writing a totally independent application is that you are doing just that, you need to build everything in the application whereas in the CMS there are already a lot of things in place. (The good part of that is that you can make new code with no legacy concerns.) For example, if you look at the JIssues project you'll see that they had to think about things like authentication. So as you would expect writing a simple application is simple, writing a complex one is complex.
You can see many examples of framework applications around, ranging from the ones found in the CLI folder of your CMS installation to JIssues, and of course the three web applications in the CMS are all examples of applications on the framework.
The Joomla Framework is intended (among other things) to be the platform upon which you can build a web-application. The framework is like the frame of one of those motorcycles they build on "American Choppers." It provides the backdrop so that you can hit the ground thinking about your app without worrying about User Authentication, database connection, and a thousand other things like those that get in the way of bringing your app to its potential audience.
If you're trying to extend Joomla, the current edition is what you should be using.
I am writing my first joomla component and while I'm getting the hang of how joomla works, I don't know how I can effectively debug and run tests on my component before installing it in joomla. So my question is: How do you go about writing a joomla component. What parts should I write first and how do I test them?
Example: A component that gets information from database and displays it. How can I write the database part (model) and test it to see if it works as expected, without having to write the rest of the component (view and controller)?
First you need to understand how to setup your machine for development. You don't need a complete component to install it on Joomla!
This is by no means a complete answer, just a few directions which you can follow:
1. Developing - Understand how Joomla! works: as a beginner before going to much harder material, it's important to get your component to work first (starting isn't easy). Learn how to use the Joomla! Platform / Framework to build your components, check code in the core components.
2. Unit Testing - After you have a working component, if you want to test parts of it, do some search on the topic Unit Testing / PHPUnit. The article How to use PHPUnit in Joomla helped me a lot on how to test a method from a controller / model I've built.
3. Debugging your code - learn how to use a debugger in your IDE (like XDebug or Zend Debugger).
4. System Tests - in the end you may want to automate some tasks you do manually - have a look at Selenium WebDriver
A couple of resources:
Joomla! Official Documentation
Learn the Art of Joomla!® from master developer Andrew Eddie
Joomla! Programming - By Mark Dexter, Louis Landry
I have been having some problems with a Magento site recently and am looking for a way to check the integrity of a Magento site at any given point.
Unit Testing jumps out as one method of doing this but I would assume it would be a very big job to write a whole lot of tests to check everything in the site is working as it should.
Can anyone involved in unit testing and magento advise on the following:
Is it possible to test the whole site and not just custom modules -
is so some examples of tests would be amazing.
Given that the site is heavily linked to the database - how would it
be possible to fully test the site without disturbing the database
Are there any better ways to automaticlly check the integrity of a
magento site
When I say integrity i really mean that there are no faults on the site - shipping, payment etc are all working correctly.
This is a big task, however there are Magento community members who have tackled it.
The EcomDev_PHPUnit module provides a framework for unit testing Magento, but it doesn't contain any actual tests. It could (and has) been used to test core functionality or modules that you have developed yourself.
One of the key advantages of the EcomDev module is that it does provide 100% isolation of your database. It creates an exact copy of your database structure, and then uses fixtures (see pg 6 of the manual) to insert data into those tables to create test pre-requisites. This is powerful and best practice, but does require quite a bit of setup.
You can try using phpMyAdmin to export data into YAML in readiness for creating fixtures.
The alternative is to create and automate a comprehensive Selenium test suite for the browser UI. In fact, the best solution is to prepare both unit and UI tests as there will be areas that can only be tested in one functional domain. There is a significant amount of business logic built into Magento's Javascript (all the validation.js for example) that PHPUnit can't easily test, Selenium is your best option here.
There have been early conversations about creating a repository of unit tests to cover the core functionality, however keep in mind that Magento 2.0 (planned for 2012) advertises complete test coverage.
I have recently started working on an eCommerce site for a company and they have selected Magento 1.4.0 to run their store. I have spent most of my PHP "career" working with various MVC frameworks (even Zend with Magento is supposed to be based on) but the complexity of Magento seems to be on another level with no seemingly good resources to look to for help.
Looking around the site I have seen suggestions for certain books to use as reference, but they all refer to Magento 1.2 or 1.3.
My goal is to develop for Magento in a way that I do not alter any of the base code so that the client can easily upgrade the version of Magento and just "drop in" my code and have it work. The current issue is how to properly use the layout/template breakdown correctly and how to add custom model/controller functionality to the application without hacking away at Magento's core code base.
how to properly use the layout/template breakdown correctly
What you need to know is the folder structure of the Magento & the use of its own MVC structure. This is a very very important part to get you started from the basic roots. Whatever version you use, the folder structure & the MVC structure followed by Magento will almost never change. Try to follow the Magento's own Knowledge Base & Wiki tutorials. If you want you can also follow some other sites as well.
how to add custom model/controller functionality to the application
without hacking away at Magento's core code base
You will need to use the custom module functionality to override the core code base of model / controller. It's a simple process of writing the main logic in a XML file, of what core class you want to override of Magento, in your module's "etc" folder. Try to understand the process first, from the Knowledge Base & Wiki tutorials, to get a firm grip on overriding core classes.
I hope this helps.