PHP – Teste Unitário com PHPUnit

Seguindo a ideia do último post, onde falei sobre o equívoco de alguns em achar que PHP não é uma linguagem para sistemas robustos, vou falar brevemente sobre o PHPUnit.
Teste unitário não é nem questão de ferramenta e sim do próprio programador, ou da política da empresa onde se trabalha.
Digo isso, porque ainda é comum hoje em dia modelos de empresas que utilizam o famoso XGH, onde nada importa, a não ser ganhar dinheiro e entregar o sistema.

No mundo PHP, o PHPUnit é a principal ferramenta para testes unitários.
A instalação é bem simples, e utilizando o NetBeans como IDE fica mais fácil ainda.
Abaixo segue um passo a passo:

Para instalar o PHPUnit é preciso ter o Pear, caso não tenha
# sudo apt-get install php-pear

Após instalar o Pear, é necessário registrar o canal no ambiente
# sudo pear channel-discover pear.phpunit.de

E enfim, instalar o PHPUnit
# sudo pear install phpunit/PHPUnit

Pronto, se tudo deu certo até aqui, o PHPUnit foi instalado com sucesso!
Agora vamos configurar para usar no NetBeans.

OBS: Estou usando a última versão do NetBeans, que hoje é 6.9.1

1 – Tools > Options e selecione a aba PHP

Tools > Options

2 – No campo PHPUnit source informe o caminho do PHPUnit, no meu caso /usr/bin/phpunit

Pronto.
Agora para testar crie um diretório em sua aplicação com o nome que desejar. Esse diretório será o repositório de seus testes.
Crie uma classe, e clique com o botão direito em cima.
Tools > Create PHPUnit tests
Selecione o diretório criado como repositório dos testes.
A partir de agora todos seus testes serão armazenados neste diretório.
Para criar novos testes, basta repetir o procedimento.

Claro que nem tudo é tão simples, é preciso entender como funciona um teste unitário, e entender a ferramenta.
Para isso > http://www.phpunit.de/manual/3.4/en/index.html

Boa sorte, e espero ter ajudado.

subscribe RSS feed!

, ,

No Comments

PHP – Debugando Aplicações com Xdebug e NetBeans

subscribe RSS feed!

1 Comment

Zend – registerAutoload is deprecated

subscribe RSS feed!

,

No Comments

Javascript – Recursão para executar N vezes uma função

Para quem gosta de desafios de programação em Javascript, encare esse post como um, senão encare apenas como uma dica mesmo.
Se encarou como desafio, tente implementar uma solução diferente(melhor?) para o problema:
- Criar uma função genérica (leia-se reuzável) que execute uma determinada função X vezes em Y milisegundos.
Sacaram a ideia?
Imaginem uma aplicação onde precisamos chamar diversas vezes uma função em um determinado intervalo.
Este é o desafio, porém o legal é fazer isso em uma única função e sem usar variáveis auxiliares.
Read the rest of this entry »

subscribe RSS feed!

No Comments

jQuery – Custom Expressions

O jQuery é uma excelente biblioteca, e suas constantes atualizações e profissionalismo fazem com que nós programadores tenhamos uma potente arma na mão para solucionar qualquer problema.
Mas mesmo o jQuery sendo tão completo, sempre haverá alguma situação ímpar em que ele não suprirá sua necessidade.
Um dos motivos que levou o jQuery a chegar ao nível de biblioteca Javascript mais utilizada do mundo, além de sua excelente performance e extremo profissionalismo foi a facilidade e possibilidade de extender suas funcionalidades.
Hoje já são incontáveis os plugins que  existem para o jQuery.

Read the rest of this entry »

subscribe RSS feed!

No Comments

Dissemine o conhecimento

subscribe RSS feed!

2 Comments

nodeJS – Installation

Como comentado no post anterior, agora o objetivo é fazer um passo a passo para instalação do nodeJS em seu ambiente.

Em teoria o node suporta todos os sistemas operacionais POSIX inclusive o Windows, mas segundo o site oficial, no momento o node está sendo testado no Linux, Mac e Solaris.

Para rodar o node é necessário ter o Python 2.4 ou superior instalado.

Levando em consideração que o V8 vem incluído no pacote do node, não existe nenhuma outra dependência.

A instalação do node não é nada complexa, porém exige alguns cuidados.

Estou no Ubuntu, e seguindo as instruções do site, de primeira não funcionou.

Agradeço aqui ao Ricardo Tomasi pelas dicas sobre a instalação do node.  ;)

Read the rest of this entry »

subscribe RSS feed!

, ,

No Comments

nodeJS – Introduction

There are times that I think about testing nodeJS, but just this week I could stop and spend some time for this goal.

My intention with this post is just compile some information about the node and pass on to those who have not had the opportunity to meet.

What motivated me to investigate the node, was the name. nodeJS.

Just as every JavaScript lover, i always want to know everything about the language, as well as what is being done with it.

What really caught my attention was the word: ”Server-side Javascript“. \o/

Yes, that’s it. Javascript running at server.

What also impressed me was the fact that there are several implementations of this type. Are almost 50 [link above].

Read the rest of this entry »

subscribe RSS feed!

,

No Comments

Creating a Task System with TheWebMind

Today start a series of posts where I want to show the power of TheWebMind to create an application.

With the last release, a major new feature is the native module Zend Models, that generates an MVC application using  Zend Framework.

Currently TheWebMind is in Pre-Alpha version, that means that is not yet fully stable, it still has bugs and improvements to be implemented.

But with what we have today, you can do a lot. And that’s what I want to share.

I assume that those who are following the tutorial already know what is TheWebMind, and know the theory behind it all.

Otherwise go to the page of documentation: http://docs.thewebmind.org/index.php?title=Main_Page

My proposal is to create a simple task system.

Requirements:

The system must allow the user registration.

The user must have a name

The task must have title, description, date and a User linked.

The system must allow the registration of multiple tasks to a User.

The system must have interface for viewing and editing of data, both users and tasks.

In short, it is a very simple system where the User registers its tasks.

Step 1 – Creating a project inTheWebMind

To create a project, go to the menu File > New Project and complete the project data.

PS: Make sure you have a database installed and configured on your server, and fill out the data, stating the address, name, port, User and password database.

These are information that TheWebMind uses to generate the tables.

Step 2 – Writing in WML

Created the project, let’s write the WM code, that meets the requirements.

The syntax of WML is based on the NLP concept (Natural Language Processing), that basically consists of being similar to natural human language (English, Portuguese, Spanish, etc).

More details in the documentation: http://docs.thewebmind.org/index.php?title=Web-Mind-Language



We know that person has a name:string(100);
The task has title:string(100);
The task has description:text();
The task has date:date();
The person has task;

 

Step 3 - Viewing the output

Click in the button bt_play_over located in the task bar above the editor.

After “compiled” the project, you can see the outputs as ER diagram, Data Dictionary, and the SQL pane tabs below the editor.

Step 4 – Generating the project

To generate the project click on compiler_over also located in the task bar above the editor.

A Wizard screen will open, leading the User until the end.

At Step 1 select the second option, indicates that the database development previously registered on the screen to create the project.

Go to the next step by clicking Next.

A screen with all the modules will be displayed in Step 2, select ZendModels and proceed to the next step.

At Step 3 are 2 options related to the TheWebMind will do about the database.

This option should be selected carefully, because if you select the “be replaced,” the TheWebMind will delete the existing table, and all your data and create a new one with the necessary changes.

The “be skipped” ignores any change in the database.

Now click in Finish, and follow the screen where the TheWebMind shows everything that is happening, and copy necessary files, create tables.

Done. You just created a system with TheWebMind.

Step 5 – Viewing the generate project

Done all the work, the TheWebMind will display the message ”Finished, the project’s been generated here“.

A screen with the tree generated files will be displayed. You can see the contents of a file to select it.

Above the tree, click the button ”Explore Files” , this will take you to the page where the application was generated.

Step 6 -Testing Application

Following these steps have a simple operating system tasks.

To test the application generated click  here: http://source.jaydson.org/TaskList/

The ZendModels generates the forms of application, it serves to test if everything is working properly.

Well, this was a small tutorial on how to make a simple system with TheWebMind using ZendModels.

Any doubt come into contact or comment.

Below is the link to download the application generated in the example, but for a better understanding of TheWebMind suggest you do the download TheWebMind, and follow all the steps described above.

It is very easy.

Download:  http://source.jaydson.org/TaskList.rar

See another example at @felipenmoura Blog: http://felipenascimento.org/en/portugues-brasil-criando-uma-aplicacao-funcional-com-thewebmind/

subscribe RSS feed!

2 Comments

TheWebMind Pre-Alpha 2.0.0

The first post of the year could not deal with anything else than the project with whom I have dedicated much of my time.
As you may know, along with Felipe Nascimento i‘m Developer /  Leader of TheWebMind.

The project has grown over the months, and 2010 promises to be a very successful year.
Developers throughout Brazil and the world are contacting us showing interest in participating in some way TheWebMind.

Aos poucos estamos nos organizando e selecionando pessoas engajadas que possam contribuir.

Last week was a milestone for the TheWebMind. Finally after much work, we release version Pre-Alpha 2.0.0.
This version is completely different from version 1, released in 2009.
We rewrite almost all the core and a totally revamped interface.

We built a new module (ZendModels) that generates code based on the PHP Zend Framework.

Interested parties follow the link below to download:
http://thewebmind.org/download_latest

In the coming weeks I intend to post examples of use of TheWebMind, mainly using ZendModels for code generation.

subscribe RSS feed!

No Comments

Free the web