Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37495 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56603 invoked from network); 6 May 2008 13:54:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2008 13:54:25 -0000 Authentication-Results: pb1.pair.com header.from=zimnyx@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=zimnyx@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.162.176 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: zimnyx@gmail.com X-Host-Fingerprint: 209.85.162.176 el-out-1112.google.com Received: from [209.85.162.176] ([209.85.162.176:60885] helo=el-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/46-22382-11360284 for ; Tue, 06 May 2008 09:54:25 -0400 Received: by el-out-1112.google.com with SMTP id m34so866714ele.13 for ; Tue, 06 May 2008 06:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=dahuQoehMEZ+wHeQ9L2Td8kgUBakOZhSIWdMsVGa+og=; b=DJtuplm7FBehW9YO3D73C6BgIT7/+AxtseJPYL05m9dQrFy/I0xp9Ngd0fCSEzlwdf40910tV42a2oKQBVjhbyzyPRZR/rKaZQNpuF+g6Kxm/VIedaayGSgoUeYmCcsxchK/Ttwqw1M9q0YetmtWAfLplcm8JoZ4ZGfjgbgavTE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=sH11jSNWb4uxlbq+7einZPlK9hpBH2rVxF85M5qUrq+9v9BUJZck0adpzALhA2UhvID38dhuloAw1+hfS2zeOr7yUS/t5uO2pubRB0zxhEvy3fboIS0VOMKcFvnFbsymtazfdcFqyvr/keoIQJUhQIcrRE0ApMrfH4D9cWP8cAQ= Received: by 10.142.69.14 with SMTP id r14mr339583wfa.255.1210082061794; Tue, 06 May 2008 06:54:21 -0700 (PDT) Received: by 10.142.155.11 with HTTP; Tue, 6 May 2008 06:54:21 -0700 (PDT) Message-ID: <299f97600805060654k4dd76e8ana4818637ff8ae82@mail.gmail.com> Date: Tue, 6 May 2008 15:54:21 +0200 To: internals@lists.php.net Cc: indeyets@gmail.com, jared.williams1@ntlworld.com, pierre.php@gmail.com, sb@sebastian-bergmann.de In-Reply-To: <299f97600804230435o6bbf8eb2l9ca760458b949dd6@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <299f97600804230435o6bbf8eb2l9ca760458b949dd6@mail.gmail.com> Subject: Re: Unable to unit test code containing *_uploaded_file() From: zimnyx@gmail.com ("Piotr Czachur") 2008/4/23 Piotr Czachur : > Hello! > > I use PHPUnit for unit testing of my application (but this issue is > independent of PHPUnit). Tests are run from command line so it's not > way (that I can imagine) to simulate file upload, because app code > uses is_uploaded_file() to check if file was really uploaded. > In my opionion some functions for simulation of file upload in command > line script would be very handy for unit testing. > Thank you guys. I finally managed to create test case using PHPUnit and phpt. Sebastaian Bergmann has made a patch in PHPUnit trunk changeset 2863 that allows to run phpt using CGI sapi, which I'm using in this test case, so it should be included in next release. Here is very simple example, two files upload.phpt and UploadTest.php =========== UploadTest.php =========== '/usr/bin/php5-cgi')); $siute = new PHPUnit_Framework_TestSuite('Upload testing'); $siute->addTest($test); $result = PHPUnit_TextUI_TestRunner::run($siute); ?> ========= upload.phpt ========= --TEST-- Multipart Form POST Data --HEADERS-- return << --EXPECTF-- Array ( [file] => Array ( [name] => fileNameee [type] => application/octet-stream [tmp_name] => %s [error] => 0 [size] => 24 ) ) uploaded ============== Test run in terminal ============== $ php UploadTest.php PHPUnit 3.2.15 by Sebastian Bergmann. . Time: 0 seconds OK (1 test) Hurraa!