PHPT
-
Upload
ivan-rosolen-phpsp -
Category
Technology
-
view
2.315 -
download
3
description
Transcript of PHPT
PHPTPHPMS Conf 2012
IVAN ROSOLEN@ivanrosolen
http://about.me/ivanrosolen
Co-fundador do PHPSP
Equipe de inovação da ARIZONADesenvolvedor 10+ anos
PHPT• Apenas um teste por aquivo .phpt
• Testes executados em processos separados
• Diferentes configurações do PHP para cada teste
• Bugs - bug<id>.phpt
• Funções Comportamento básico - <nomedafuncao>_basic.phpt Erro - <nomedafuncao>_error.phpt Variações - <nomedafuncao>_variation.phpt
• Extensões - <nomedaextensao><numero>.phpt
Nomenclatura
--TEST-- Uma linha para descrever o teste
--FILE-- código PHP (isso mesmo PHP!)
--EXPECT--Resultado esperado (acerto ou erro)
Seções Obrigatórias
--TEST-- [--DESCRIPTION--]
[--CREDITS--] [--SKIPIF--]
[--REQUEST--] [--POST-- | --PUT-- | --POST_RAW-- | --GZIP_POST-- | --DEFLATE_POST-- | --GET--]
[--COOKIE--] [--STDIN--]
[--INI--] [--ARGS--] [--ENV--]
--FILE-- | --FILEEOF-- | --FILE_EXTERNAL-- | --REDIRECTTEST-- [--HEADERS--]
[--CGI--] [--XFAIL--]
[--EXPECTHEADERS--]--EXPECT-- | --EXPECTF-- | --EXPECTREGEX--
[--CLEAN--]
--EXPECTF--%s string
%d number
%c single char
%w whitespace
%i integer
%f floats
%x hexadecimal
%e directory sep.
Baixar o source da versão do PHP desejada
./configure (com parâmetros necessários)make
Como Fazer
make test
tar -xvf php-5.4.5.tar.gz
make test TESTS=diretorio/
Testando
make test TESTS=diretorio/*.phpt
make test TESTS=diretorio/nome.phpt
Teoricamente .zip do PHP win roda os testes com o php.exenmake test
Exemplos
--TEST--Xuplau--FILE--<?php echo 'Xuplau’; ?>--EXPECT--Xuplau
--TEST--Xuplau Error--FILE--<?php echo 'Xuplau--EXPECTF--Parse error: syntax error, unexpected '%s' (T_ENCAPSED_AND_WHITESPACE) in %s.php on line %d
--TEST--Xuplau Error--FILE--<?php echo 'Xuplau--EXPECTREGEX--Parse error: (syntax|parse) error, unexpected .* \(T_ENCAPSED_AND_WHITESPACE\) in .* on line \d
--TEST--Apagar TMP Files--FILE--<?php$tmp = dirname(__FILE__) . '/foo.tmp';$fp = fopen($tmp, 'w');fwrite($fp, 'bar');fclose($fp);?>--CLEAN--<?php$tmp = dirname(__FILE__) . '/foo.tmp';unlink($tmp)?>--EXPECT--
--TEST--Skipif teste!--SKIPIF--<?phpif ( substr(PHP_OS, 0, 3 ) != 'WIN') die('Teste apenas para Unix');?>--FILE----EXPECT--
--TEST-- Testing imagerectangle() of GD library --CREDITS-- Ivan Rosolen <contato [at] ivanrosolen [dot] com> #testfest PHPSP on 2009-06-30--SKIPIF-- <?php if ( ! extension_loaded('gd') ) die( 'skip GD not present; skipping test' ); ?> --FILE--<?php// Create a image $image = imagecreatetruecolor( 100, 100 );
// Draw a rectangleimagerectangle( $image, 0, 0, 50, 50, imagecolorallocate($image, 255, 255, 255) );
ob_start(); imagepng( $image, null, 9 ); $img = ob_get_contents(); ob_end_clean();
echo md5(base64_encode($img));
?> --EXPECT-- 282aaecfdd50091821d63093d9bb1bb9
--TEST--Testing wrong param passing imagefilledellipse() of GD library--CREDITS--Ivan Rosolen <contato [at] ivanrosolen [dot] com>#phpsptestfest PHPSP on 2010-05-29--SKIPIF--<?php if (!extension_loaded("gd")) die("skip GD not present");?>--FILE--<?php
// Create a image$image = imagecreatetruecolor(400, 300);
// choose a color for the ellipse$ellipse = imagecolorallocate($image, 255, 255, 255);
// draw the white ellipseimagefilledellipse( 'wrong param', 200, 150, 300, 200, $ellipse);
?>--EXPECTF--Warning: imagefilledellipse() expects parameter 1 to be resource, %s given in %s on line %d
*.exp
*.log
*.out
*.php
*.phpt
*.sh
Deu erro!
*.diff
PHPT +• Suas extensões
• Seus Projetos
https://github.com/vrana/notorm
• Clonar git https://github.com/php/php-src
• Pull Request
• Avisar na lista do QA
Quality Assurance list - [email protected]
Enviando Testes
http://gcov.php.net
http://qa.php.net/write-test.php
Links
https://wiki.php.net/qa/testfest-2010/windows-test-environment
Para Windows ( não testei muito ainda )
http://pastebin.com/PPBr05kQ
http://pastebin.com/CxFtXUwS
http://php.net/mailing-lists.php
Dúvidas?