Mittwoch, 28. November 2012

Probleme mit PHPUnit

Bei mir lief das aktualisieren der PHPUnit nicht. Es kam immer die folgende Ausgabe:

PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 650

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 650
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 697

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 697
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 757

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 757
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 786

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 786
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 914

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 914
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 1577

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 1577
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 1607

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 1607
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 2038

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 2038
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Config.php on line 2091

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Config.php on line 2091
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Registry.php on line 322

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Registry.php on line 322
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Registry.php on line 1450

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Registry.php on line 1450
PHP Deprecated:  Assigning the return value of new by reference is deprecated in
 C:\xampp\php\PEAR\PEAR\Registry.php on line 1458

Deprecated: Assigning the return value of new by reference is deprecated in C:\x
ampp\php\PEAR\PEAR\Registry.php on line 1458
PHP Strict Standards:  Non-static method System::tmpdir() should not be called s
tatically in C:\xampp\php\PEAR\PEAR\Config.php on line 158

Strict Standards: Non-static method System::tmpdir() should not be called static
ally in C:\xampp\php\PEAR\PEAR\Config.php on line 158
PHP Strict Standards:  Non-static method System::tmpdir() should not be called s
tatically in C:\xampp\php\PEAR\PEAR\Config.php on line 167

Strict Standards: Non-static method System::tmpdir() should not be called static
ally in C:\xampp\php\PEAR\PEAR\Config.php on line 167
PHP Strict Standards:  Non-static method System::tmpdir() should not be called s
tatically in C:\xampp\php\PEAR\PEAR\Config.php on line 176

Strict Standards: Non-static method System::tmpdir() should not be called static
ally in C:\xampp\php\PEAR\PEAR\Config.php on line 176
PHP Strict Standards:  Non-static method System::which() should not be called st
atically in C:\xampp\php\PEAR\PEAR\Config.php on line 229

Strict Standards: Non-static method System::which() should not be called statica
lly in C:\xampp\php\PEAR\PEAR\Config.php on line 229
PHP Strict Standards:  Non-static method Console_Getopt::getopt() should not be
called statically, assuming $this from incompatible context in C:\xampp\php\PEAR
\PHPUnit2\TextUI\TestRunner.php on line 154

Strict Standards: Non-static method Console_Getopt::getopt() should not be calle
d statically, assuming $this from incompatible context in C:\xampp\php\PEAR\PHPU
nit2\TextUI\TestRunner.php on line 154
PHP Strict Standards:  Non-static method Console_Getopt::doGetopt() should not b
e called statically, assuming $this from incompatible context in C:\xampp\php\PE
AR\Console\Getopt.php on line 78

Strict Standards: Non-static method Console_Getopt::doGetopt() should not be cal
led statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Co
nsole\Getopt.php on line 78
PHP Strict Standards:  Non-static method PEAR::isError() should not be called st
atically, assuming $this from incompatible context in C:\xampp\php\PEAR\Console\
Getopt.php on line 87

Strict Standards: Non-static method PEAR::isError() should not be called statica
lly, assuming $this from incompatible context in C:\xampp\php\PEAR\Console\Getop
t.php on line 87
PHP Strict Standards:  Non-static method PEAR::isError() should not be called st
atically, assuming $this from incompatible context in C:\xampp\php\PEAR\PHPUnit2
\TextUI\TestRunner.php on line 160

Strict Standards: Non-static method PEAR::isError() should not be called statica
lly, assuming $this from incompatible context in C:\xampp\php\PEAR\PHPUnit2\Text
UI\TestRunner.php on line 160
PHPUnit 2.3.6 by Sebastian Bergmann.

Usage: phpunit [switches] UnitTest [UnitTest.php]
  --testdox-html   Write agile documentation in HTML format to file.
  --testdox-text   Write agile documentation in Text format to file.
  --log-xml        Log test progress in XML format to file.

  --loader       TestSuiteLoader implementation to use.

  --skeleton             Generate skeleton UnitTest class for Unit in Unit.php.

  --wait                 Waits for a keystroke after each test.

  --help                 Prints this usage information.
  --version              Prints the version and exits.




Um drotzdem Testen zu können habe ich den folgenden Weg gefunden:

Die Datei phpunit.Phar Herunterladen. Dies geht einfach mit Firefox die folgende URL öffen:
http://pear.phpunit.de/get/phpunit.phar (Firefox fragt bei mir dann gleich ober die Datei Speichern soll)

Wenn man dann PHPUnit nutzen möchte ruft man die Datei wie folgt in der Komandozeile(Windows) auf:
php Laufwerk:\pfad_zum_file\phpunit.phar
(Man muß sich nur in dem Verzeichnis befinden, wo die phpunit.xml.dist und bootstrap.php liegen) Die benötigten Dateien vom Test sucht sich das Programm dann selbst zusammen.

Zend Framework2 -Unit Testing - Setting up the tests directory

Für das Unit Testing bzw. die Verzeichnisstruktur erstellen habe ich mir eine kleine Batchdatei geschrieben, die die Verzeichnisstruktur erstellt. Mit dem Inhalt:

md test
md test\ApplicationTest
md test\ApplicationTest\Controller


Diese wird nachdem man die Skeleton Application Installiert hat in dem Verzeichnis
zf2-tutorial2\module\Application ausgeführt.

Die Namen der Verzeichnisse müßen dann noch auf die jeweilige Anwendung angepasst werden.(Also alles was zf2-tutorial2 lautet)

Dienstag, 27. November 2012

pear upgrade - ERROR: failed to Makedir

Will man PEAR aktualisieren kommt es mit unter zu der Meldung "Error: failed to Makedir".

Dies lag bei mir daran, das Windows bzw. Pear das Verzeichnis nicht Richtig zugeordnet hat. Die Lösung:

Die Kommandozeile aufrufen (XP: Start - ausführen: CMD bzw. W7:Start in das Feld CMD eingeben und "Enter" drücken).

In das Installationsverzeichnis (auf jedem Rechner anders) von PHP wechseln:

D:
cd D:\xampp\php
 
Danach die Konfiguration anpassen(nacheinander eingeben oder einfügen und bei dem letzten Bfehl "Enter" drücken):
pear config-set doc_dir d:\xampp\php\pear\docs
pear config-set cfg_dir d:\xampp\php\pear\cfg
pear config-set data_dir d:\xampp\php\pear\data
pear config-set cache_dir d:\xampp\php\pear\cache
pear config-set download_dir d:\xampp\php\pear\download
pear config-set temp_dir d:\xampp\php\pear\temp
pear config-set test_dir d:\xampp\php\pear\tests
pear config-set www_dir d:\xampp\php\pear\www

Nun noch aktualisieren:
pear upgrade pear

Dienstag, 8. März 2011

PHP und UTF-8 Umlaute fehler

Es gibt einige unschöne seiteneffeket wenn man bei Php mit UTF-8 konfrontiert wird. Das noch nervigere ist, das der Browser(in meinem Fall Firefox) versucht das Format selbst zu erkennen, d.h. erkennt der Browser eine Ausgabe als UTF-8 wird alles was ISO ist falsch dargestellt und immer umgegkehrt.

Fazit:
Da Php mit UTF-8 probleme hat immer beim bearbeiten von UTF-8 strings die ersatzstrinfunktionen benutzen (mb_strlen etc.) und Ausgaben nicht mixen - sonst Klapse net weit!

Montag, 7. März 2011

PHP: Notice: Unknown: Invalid quoted-printable sequence:

Wenn man versucht eine base64 - codierte mail mit imap_qprint() zu decodieren bekommt man die Fehlermeldung:

Notice: Unknown: Invalid quoted-printable sequence: =_NextPart_???? Content-Type: text/plain; charset="iso-8859-1 (errflg=3) in Unknown on line 0

Wobei ??? für den Delimiter steht. Dies kann abgefangen werden mit:


$parts=explode("base64",$emailstring);
if (1{
$partsa=explode("------",$parts[1]);
$emailstring=base64_decode($partsa[0]);
$emailstring=utf8_decode($emailstring);
}
else
{
$emailstring=imap_qprint($emailstring);//decodieren der nachricht
}

Allerdings wird hier nur der erste Teil der Mime-Mail übersetzt - wahrscheinlich gibt es bessere Lösungen war jedoch die am schnellsten mir eingefallen ist. Eine suche nach PHP Mime base64 ergibt bestimmt noch andere lösungen.

PHP - imap_setflag_full funktioniert nicht

Nach langer suche - man muß bei imap_setflag_full auf die groß und kleinschreibung achten ein Flag \\answered funktioniert nicht nur \\Answered.

Freitag, 17. September 2010

DBF - Dateien erstellen/bearbeiten Teil 2

Unter http://php.net/manual/de/ref.dbase.php habe ich den folgenden Code gefunden:



function get_dbf_header($dbfname) {
$fdbf = fopen($dbfname,'r');

$dbfhdrarr = array();
$buff32 = array();
$i = 1;
$goon = true;

while ($goon) {
if (!feof($fdbf)) {
$buff32 = fread($fdbf,32);
if ($i > 1) {
if (substr($buff32,0,1) == chr(13)) {
$goon = false;
} else {
$pos = strpos(substr($buff32,0,10),chr(0));
$pos = ($pos == 0?10:$pos);

$fieldname = substr($buff32,0,$pos);
$fieldtype = substr($buff32,11,1);
$fieldlen = ord(substr($buff32,16,1));
$fielddec = ord(substr($buff32,17,1));

array_push($dbfhdrarr, array($fieldname,$fieldtype,$fieldlen,$fielddec));

}
}
$i++;
} else {
$goon = false;
}
}

fclose($fdbf);
return($dbfhdrarr);
}

$arr = get_dbf_header('/data/file.dbf');
print_r($arr);
?>



nachdem auslesen der Header zeilen habe ich mir den rest in einem weiteren feld des Arrays erstellt.

$rest=$buff32.fread($fdbf, filesize($dbfname));
$dbfhdrarr[]=$rest;

nun kann man mit etwas String bearbeitung und einer Foreach schleife jedes Feld ändern.

Filename ist der Name der Originalen dbf-Datei.
Hier der komplette Code:


function get_dbf_header($dbfname) {
$fdbf = fopen($dbfname,'r');

$dbfhdrarr = array();
$buff32 = array();
$i = 1;
$j = 2;
if ($fdbf) $goon = true;

while ($goon)
{
if (!feof($fdbf))
{
$buff32 = fread($fdbf,32);
if ($i > 1)
{
if (substr($buff32,0,1) == chr(13))
{
$goon = false;
} else
{
$pos = strpos(substr($buff32,0,10),chr(0));
$pos = ($pos == 0?10:$pos);

$fieldname = substr($buff32,0,$pos);
$fieldtype = substr($buff32,11,1);
$fieldlen = ord(substr($buff32,16,1));
$fielddec = ord(substr($buff32,17,1));

array_push($dbfhdrarr, array('feldname'=>$fieldname,'feldtyp'=>$fieldtype,'feldlang'=>$fieldlen,'felddec'=>$fielddec));

}
}
else
{
$anfang=$buff32;
}
$i++;
} else {
$goon = false;
}
}
$rest=$buff32.fread($fdbf, filesize($dbfname));
$dbfhdrarr[]=$rest;

fclose($fdbf);
return($dbfhdrarr);
}

function GetRealSize($file) {
// Return size in Mb
clearstatcache();
$INT = 4294967295;//2147483647+2147483647+1;
$size = filesize($file);
$fp = fopen($file, 'r');
fseek($fp, 0, SEEK_END);
if (ftell($fp)==0) $size += $INT;
fclose($fp);
if ($size<0) $size += $INT;
return $size;
}

//-------------------------------------------------
//Werte Auslesen und Anpassen
//-------------------------------------------------


$arr = get_dbf_header($filevalue['filename']); //Kopfzeilen der DBF Auslesen
$rest=$arr[$filevalue['werteindex']]; //Werte der Zellen stehen in array Index 164




if (substr($rest,0,2)!=(chr(13).chr(32)))
{
$rest=chr(13).chr(32).substr($rest,265);
}


$speichern=chr(13).chr(32);//Zeilenumbruch und Leerzeichen vor erstem Datensatz
foreach ($arr as $key=>$value)
{
if (0==$key)
{
$wert=trim(substr($rest,2,($value['feldlang'])-2)); //Wert holen
$rest=substr($rest,($value['feldlang']+2)); //Restlichen String kürzen
}
else
{
$wert=trim(substr($rest,0,$value['feldlang'])); //Wert holen
$rest=substr($rest,$value['feldlang']); //Restlichen String kürzen
}
switch ($key)
{
case 0: $wert=''; //
break;
case 1: $wert=date('dmY'); //Datum
break;
case 2:
break;
case 3:
case 4:
}
}