Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Estas en el tema de PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase en el foro de PHP en Foros del Web. Buenas... Hace tiempo vengo usando PHPUnit_Framework_TestCase pero recien descubro PHPUnit_TestCase y me pregunto si realmente justifica ese framework (?) Hay que escribir mucho codigo adicional ...
  #1 (permalink)  
Antiguo 27/04/2014, 13:41
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Buenas...

Hace tiempo vengo usando PHPUnit_Framework_TestCase pero recien descubro PHPUnit_TestCase y me pregunto si realmente justifica ese framework (?)

Hay que escribir mucho codigo adicional para hacer las pruebas y hasta ahora las unicas ventajas que vi son:

- addTest() para poder controlar que metodos van a las pruebas (lo cual puede ser canson tambien)

- toHTML() y toString() .. en vez del implicito toString() en PHPUnit_Framework_TestCase


Bueno..dejo las dudas planteadas

Gracias!
__________________
Salu2!
  #2 (permalink)  
Antiguo 27/04/2014, 15:20
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

No entiendo muy bien la duda, pero la clase que acabas de descubrir pertenece a phpunit 1.x el cual esta deprecated hace mucho tiempo(7 años)
__________________
http://es.phptherightway.com/
thats us riders :)
  #3 (permalink)  
Antiguo 27/04/2014, 15:59
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
Respuesta: PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Cita:
Iniciado por masterpuppet Ver Mensaje
No entiendo muy bien la duda, pero la clase que acabas de descubrir pertenece a phpunit 1.x el cual esta deprecated hace mucho tiempo(7 años)
En el PHPUnit 4.x sigue ahi..... y no da error E_DEPRECATED ni nada ......

Lo que quiero preguntar es cual seria la mejor forma de trabajar hoy ? con cual clase ?
__________________
Salu2!
  #4 (permalink)  
Antiguo 27/04/2014, 16:52
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Es que yo no veo la clase que tu mencionas(si no te estoy entendiendo PHPUnit_TestCase), podrias indicar donde lo ves de esa forma ?, en el branch master dicha clase no existe https://github.com/sebastianbergmann...ree/master/src, o talves te estoy entendiendo mal ?, en cualquier caso por regla general(independientemente de la libreria) es mejor utilizar la última version estable.
__________________
http://es.phptherightway.com/
thats us riders :)
  #5 (permalink)  
Antiguo 27/04/2014, 17:53
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
Respuesta: PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Voy a dar el tema por solucionado..... me baje phar.phar.bat del sitio oficial y lo instale, ahi tengo esa clase y hasta hay un ejemplo en la documentacion oficial:

Código PHP:
Ver original
  1. <?php
  2. require_once 'PHPUnit.php';
  3.  
  4. class MathTest extends PHPUnit_TestCase {
  5.     var $fValue1;
  6.     var $fValue2;
  7.  
  8.     function MathTest($name) {
  9.       $this->PHPUnit_TestCase($name);
  10.     }
  11.  
  12.     function setUp() {
  13.       $this->fValue1 = 2;
  14.       $this->fValue2 = 3;
  15.     }
  16.  
  17.     function testAdd() {
  18.       $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
  19.     }
  20.    
  21.     function testSub() {
  22.       $this->assertTrue($this->fValue2 - $this->fValue1 == 1);
  23.     }
  24. }
  25.  
  26. $suite = new PHPUnit_TestSuite();
  27. $suite->addTest(new MathTest('testAdd'));
  28. $suite->addTest(new MathTest('testSub'));
  29.  
  30. $result = PHPUnit::run($suite);
  31. print $result->toString();
  32. #print $result->toHTML();

Si te fijas... puedes enviar a consola con ->toString() al browser con ->toHTML()

Lo otro que decia... es que permite registrar con addTest() los metodos a probar ... pero se me hace mas simple con la otra clase:

Código PHP:
Ver original
  1. <?php
  2. require_once 'PHPUnit.php';
  3.  
  4. class MathTest extends PHPUnit_Framework_TestCase {
  5.     var $fValue1;
  6.     var $fValue2;
  7.  
  8.     function MathTest($name) {
  9.       $this->PHPUnit_TestCase($name);
  10.     }
  11.  
  12.     function setUp() {
  13.       $this->fValue1 = 2;
  14.       $this->fValue2 = 3;
  15.     }
  16.  
  17.     function testAdd() {
  18.       $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
  19.     }
  20.    
  21.     function testSub() {
  22.       $this->assertTrue($this->fValue2 - $this->fValue1 == 1);
  23.     }
  24. }
__________________
Salu2!
  #6 (permalink)  
Antiguo 27/04/2014, 19:17
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Si lo tiene claro marque como solucionado el tema nomas, de todas formas dado que yo realmente no lo tengo claro y me gustaria saber que sucede, serias tan amable de postear los links de lo que has instalado ?
__________________
http://es.phptherightway.com/
thats us riders :)
  #7 (permalink)  
Antiguo 27/04/2014, 19:45
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
Respuesta: PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Ya.... Ud tenia razon ! es muy viejo......

Cita:
Class: PHPUnit

Source Location: /PHPUnit-1.3.2/PHPUnit.php

Class Overview


PHPUnit runs a TestSuite and returns a TestResult object.


Author(s):

Sebastian Bergmann <mailto:sb at sebastian-bergmann.de>
Version:

Release: @package_version@
Copyright:

2002-2005 Sebastian Bergmann <[email protected]>
Methods

run
Inherited Variables

Inherited Methods

Class Details

[line 109]
PHPUnit runs a TestSuite and returns a TestResult object.
Here is an example:


1 <?php
2 require_once 'PHPUnit.php';
3
4 class MathTest extends PHPUnit_TestCase {
5 var $fValue1;
6 var $fValue2;
7
8 function MathTest($name) {
9 $this->PHPUnit_TestCase($name);
10 }
11
12 function setUp() {
13 $this->fValue1 = 2;
14 $this->fValue2 = 3;
15 }
16
17 function testAdd() {
18 $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
19 }
20 }
21
22 $suite = new PHPUnit_TestSuite();
23 $suite->addTest(new MathTest('testAdd'));
24
25 $result = PHPUnit::run($suite);
26 print $result->toHTML();
27 ?>
Alternatively, you can pass a class name to the PHPUnit_TestSuite() constructor and let it automatically add all methods of that class that start with 'test' to the suite:


1 <?php
2 $suite = new PHPUnit_TestSuite('MathTest');
3 $result = PHPUnit::run($suite);
4 print $result->toHTML();
5 ?>
Link: http://pear.php.net/package/PHPUnit
Since: Class available since Release 1.0.0
Version: Release: @package_version@
License: BSD License
Copyright: 2002-2005 Sebastian Bergmann <[email protected]>
Author: Sebastian Bergmann <mailto:sb
http://pear.php.net/package/PHPUnit/...t/PHPUnit.html
__________________
Salu2!
  #8 (permalink)  
Antiguo 27/04/2014, 20:10
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: PHPUnit : PHPUnit_TestCase vs PHPUnit_Framework_TestCase

Ah, ahora me cierra, gracias, de todas formas lo oficial seria http://phpunit.de

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)

Etiquetas: phpunit
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:38.