Giter Club home page Giter Club logo

simpletest's Introduction

SimpleTest Build Status Build Status by Version Latest Stable Version Total Downloads

SimpleTest is a framework for unit testing, web site testing and mock objects for PHP.

Installation

Downloads

All downloads are stored on Github Releases.

You may find the zip of the "latest released version" here:

https://github.com/simpletest/simpletest/releases/latest

You may find the zip archive of the "main" development branch here:

https://github.com/simpletest/simpletest/archive/main.zip

Composer

You may also install the extension through Composer into the /vendor folder of your project.

Either run

php composer.phar require --prefer-dist simpletest/simpletest "^1.2"

or add the package simpletest/simpletest to the require-dev section of your composer.json file:

{
    "require-dev": {
        "simpletest/simpletest": "^1.2"
    }
}

followed by running composer install.

Issues

Please report all issues you encounter at Github Issues.

Community

Feel free to ask a new question on Stack Overflow or at Github Issues.

StackOverflow offers also a good collection of SimpleTest related questions.

Requirements

PHP 7.1+

Authors

License

GNU LGPL v2.1

Tests

The unit tests for SimpleTest itself can be run here:

tests/all_tests.php

The acceptance tests require a running server:

- php -S localhost:8080 -t tests/site
- tests/acceptance_test.php

Docs

https://simpletest.org/en/first_test_tutorial.html

simpletest's People

Contributors

asmundstavdahl avatar bitfrei avatar bytestream avatar cambell-prince avatar chellem avatar chrisgraham avatar crishoj avatar dependabot[bot] avatar ezyang avatar irahopkinson avatar jakoch avatar lox avatar mal avatar oxicode avatar perrick avatar pharazon avatar ppaulis avatar still-dreaming-1 avatar vaceletm avatar vickrum avatar vierbergenlars avatar weberhofer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simpletest's Issues

Failed unit_tests.php

Just installed simpleTest 1.1.7 on the XAMPP htdocs directory on Windows 7(unziping to it) and got this message after running unit_tests.php. Is there a need to configure any dependency ?

unit_tests.php
Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\mock_objects.php line 512]

Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\mock_objects.php line 512]

Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\mock_objects.php line 774]

Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\mock_objects.php line 774]

Fatal error: Uncaught ArgumentCountError: Too few arguments to function MockDummyInterface::anotherMethod(), 0 passed in
C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\test\interfaces_test.php on line 33 and exactly 1 expected in C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\mock_objects.php(1403) : eval()'d code:10 Stack trace: #0

C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\test\interfaces_test.php(33): MockDummyInterface->anotherMethod() #1

C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\invoker.php(72): TestOfMockInterfaces->testMockedInterfaceExpectsParameters() #2 C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\invoker.php(136): SimpleInvoker->invoke('testMockedInter...') #3

C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\exceptions.php(44): SimpleInvokerDecorator->invoke('testMockedInter...') #4

C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\invoker.php(136): SimpleExceptionTrappingInvoker->invoke('testMockedInter...') #5

C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7 in C:\ArquivosDeProgramas\xampp\htdocs\simpleTest_1_1_7\mock_objects.php(1403) : eval()'d code on line 10

When install through Composer, I get this:

unit_tests.php
Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\mock_objects.php line 512]
Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\mock_objects.php line 512]
Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\mock_objects.php line 774]
Exception: Unit tests -> C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\test/mock_objects_test.php -> TestOfMockExpectations -> testNonArrayForExpectedParametersGivesError -> Unexpected PHP Error [count(): Parameter must be an array or an object that implements Countable] severity [2] in [C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\mock_objects.php line 774]

Fatal error: Uncaught ArgumentCountError: Too few arguments to function MockDummyInterface::anotherMethod(), 0 passed in C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\test\interfaces_test.php on line 33 and exactly 1 expected in C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\mock_objects.php(1403) : eval()'d code:10 Stack trace: #0 C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\test\interfaces_test.php(33): MockDummyInterface->anotherMethod() #1 C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\invoker.php(72): TestOfMockInterfaces->testMockedInterfaceExpectsParameters() #2 C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\invoker.php(136): SimpleInvoker->invoke('testMockedInter...') #3 C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\exceptions.php(44): SimpleInvokerDecorator->invoke('testMockedInter...') #4 C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpl in C:\ArquivosDeProgramas\xampp\htdocs\projIni\vendor\simpletest\simpletest\mock_objects.php(1403) : eval()'d code on line 10

New Release / Project Status

I would like to inquire about the status of simpletest. The last release was in October of 2015, so getting close to 2 years ago now. I'm guessing there are 4 possibilities as to why this is. 1) The code has been unfit for release since then. 2) There have not been significant enough changes to warrant a release. 3) The project is not actively maintained enough for someone to prepare a release even though they are believed in by the maintainer. 4) You don't believe in releases and always consider the master branch to be the latest release and fit for use.

Syntax error in mocked methods in PHP 7.1+

Replacing my ancient bug report with an up-to-date one:

reflection.php has code for generating a nullable return type in a method signature, but the code seems to have 2 problems:

  1. It doesn't actually use allowsNull() on the return type object, so it looks like all types would be marked nullable
  2. More relevantly, It doesn't check to see if getReturnType returns null (or is empty string in the casted-to-string form it's currently being used), so in that case it generates a signature with just a floating : ?, which causes a syntax error when the code gets eval'd in a mock class.

Just removing the whole block removes the syntax error and is probably a step forward.

ReferenceExpectation scalar bug

Transfering my comment from the now defunct #8 to an issue to be actively looked into.

tl;dr

  • #7 fundamentally broke ReferenceExpectation for everything but objects.
  • #5 achieves the goals of #7 in the simplest way possible without breaking anything.
  • Please revert #7 and consider re-opening/merging #5. PR can be found in #11.

Hmmm, seems those fails are valid. Looking at them I also suspect that #7 has introduced some potential pit falls. I think perhaps #5 was the way to go after all.

Problem is those ampersands are needed (objects are implicitly byref in PHP5, but scalars and arrays are not). Unfortunately that means it can't inherit (warnings to do with differing method signatures) so the separate class and just tweaking the isExpectation method was probably the safest change afterall!

Recommend reopening #5 and reverting #7 merging #11.

Sorry for the confusion ๐Ÿ˜ž

Using percent sign in assert message

Because of message formatting uses sprinf, assert methods fail if the message contains percent sign:

Unexpected PHP Error [sprintf(): Too few arguments] severity [2] in [/media/sf_projects/html/simpletest2/test_case.php line 311]

Status & Todo

I've done some commits to get SimpleTest up and running on Travis-CI.
This build is the first green one after a long time. And yes, it's green on PHP 7 ;)
https://travis-ci.org/simpletest/simpletest/builds/73022256


Warning: tl;tr

  • I've disabled the acceptance_tests. They do live tests against lastcraft.com, which is down.
    This needs to be changed:
  • fire up PHP server or Nginx over at Travis
  • serve the tests folder for the acceptance tests
  • alter the lastcraft.com to localhost
  • The Mock object creation is still a mess. Some mocks use the method name of their class as constructors. This will be deprecated soon and is now a warning.
  • I've prefixed several failing tests with "TODO_".
    Some of them are related to the SimpleTestCompatibility::isReference() function.
    I think the reference detection needs an adjustment to work with newer PHP versions.
  • I've dropped several PHP version comparisons and guards with the intention to raise the minimum PHP version to PHP 5.4. All lower PHP versions are EOL and PHP5.4 itself is EOL at the end of 2015.
  • I've also removed several compatibility functions and inserted the native functionality at the position of the call to the compat functions.

Regards, Jens

TestSuite ends up creating instances of the clases in the hiearchy of a test

Hi,

We're having an issue with the way classes are handled when building a TestSuite.

We have a hierarchy of test classes that eventually derive from testcase. Some of the classes in the hierarchy are abstract, but other aren't. When the TestSuite is built, the non-abstract classes are added to the TestSuite and an instance of them is constructed. Those classes don't have test methods, so only the constructor is run. The problem is that their constructors perform a long initialization, which is run multiple times (once for each 'parent' class created).

Our hierarchy of classes is something like:

abstract class BaseTest extends UnitTestCase {}
class CommonTest extends BaseTest {}
class TestWithDb extends CommonTest {}
class ATest extends TestWithDb {}

When we try to run ATest, three instances are created: one of ATest (as expected), but also one of TestWithDb and one of CommonTest.

My question is what is the rationale behind it? If the class of the test has a parent class, why is the latter instantiated on its own?

The sequence of the code is:

In SimpleFileLoader:

public function load($test_file)
{
    $existing_classes = get_declared_classes();
    $existing_globals = get_defined_vars();
    include_once($test_file);
    $new_globals = get_defined_vars();
    $this->makeFileVariablesGlobal($existing_globals, $new_globals);
    $new_classes = array_diff(get_declared_classes(), $existing_classes);
    if (empty($new_classes)) {
        $new_classes = $this->scrapeClassesFromFile($test_file);
    }
    $classes = $this->selectRunnableTests($new_classes);

    return $this->createSuiteFromClasses($test_file, $classes);

}

scrapeClassesFromFile(): finds all the classes of our hierarchy.
selectRunnableTests(): marks as ignored only abstract classes
createSuiteFromClasses(): ignores only the parent of ignored classes, creates one instance of the remaining ones.

Regards,

Alejandro

Dynamic method called as static

Hello,

I think there is a problem with some dynamic methods that are called as static methods. And calling a dynamic method statically generates the E_STRICT error with PHP 5. Could you please check that and update Simpletest?

The following dynamic methods are called statically:

  • Class PageRequest, methods get() and post()
  • Class DOMDocument, method loadHTML
vendor/simpletest/simpletest/test/site/front_controller_style/show_request.php:21
vendor/simpletest/simpletest/test/site/front_controller_style/show_request.php:35
vendor/simpletest/simpletest/test/site/path/network_confirm.php:41
vendor/simpletest/simpletest/test/site/network_confirm.php:41
vendor/simpletest/simpletest/test/site/protected/network_confirm.php:41
vendor/simpletest/simpletest/test/site/path/network_confirm.php:55
vendor/simpletest/simpletest/test/site/protected/network_confirm.php:55
vendor/simpletest/simpletest/test/site/network_confirm.php:61
vendor/simpletest/simpletest/extensions/coverage/test/coverage_calculator_test.php:70
vendor/simpletest/simpletest/extensions/coverage/test/simple_coverage_writer_test.php:71

This issue is similar to issue #2.

Thanks ;)

Guillaume

[support] How to structure integration tests

I must be missing a trick with structuring my integration tests. I have classes for running specific tests based on input, but now I want to test different classes together and running into problems. I first tried inheritence but quickly realised that approach was limited when I needed to use more than 1 test class (e.g. fooTest, barTest).
I only want to run every 'test' method in bazTest, while fooTest and barTest just provide useful abstractions so that bazTest is short and understandable.

What I'm trying now is failing with Fatal error: Call to a member function getDumper() on a non-object in /srv/example.com/htdocs/simpletest/test_case.php on line 345

class bazTest extends UnitTestCase {
    function testStart() {
        $this->foo = new fooTest();
    }
    function testDo() {
        $this->foo->doFoo(true);
    }
}
class fooTest extends UnitTestCase {
    function doFoo($foo) {        $this->assertTrue($foo);    }
}
class barTest extends UnitTestCase {
    function doBar($bar) {        $this->assertTrue($bar);    }
}

I guess I'm misunderstanding some concepts, but I thought I remember reading that SimpleTest can do Integration tests and not only Unit tests..

ExpectException Needs better documentation

I recently built a test that intentionally causes an exception and capture that exception using the expectException function. I did not realize that after the exception is thrown the test is ended even if their are additional assert statements after the exception.

It took nearly an hour to figure out why my asserts were not being seen. I had to find the answer from some outdated forum that on exception the test ends. This is not listed in the official documentation. This is also very poor usability.

At the lest the documentation needs to be updated.

Better would be to remove function and force users to try/catch the exception on their own so they don't fall into the trap I did. Or best find a way for the function to capture exception and continue the test.

Website seems to be outdated

The first thing you see when you get to the website is:

[23/01/2012] SimpleTest 1.1.0 is available. It's the first release in maintenance mode.

(emphasis on date mine)

Whilst it may be true that 1.1.0 is still the only version in maintenance mode, that date is really old now. I was really happy to see that there's a Github account with activity. I only discovered this after coming across a Stack Overflow answer that mentioned the project is not abandoned.

That made me really happy as I looked for a long time to find something like this for my own testing and fell in love. I think for the sake of others who will come across the website and not realise there's activity, the above block should be moved to a less prominent location and an indicator put in off activity. Perhaps one of those snazzy "fork me on Github" banners everyone seems to like these days?

Fork me on Github ribbon

If you'd like some help with the site I'd be happy to help out or put in some PRs if you make it a public repo.

i would like commit some code

`diff --git a/browser.php b/browser.php
index 09aa295..ec25d84 100644
--- a/browser.php
+++ b/browser.php
@@ -248,7 +248,8 @@ class SimpleBrowser
}

 /**
  • * Switches back on the cookie sending and recieving.
    
  • *    Switches back on the cookie sending and recieving.
    
  • *    @access public
    */
    

    public function useCookies()
    {
    @@ -256,6 +257,27 @@ class SimpleBrowser
    }

    /**

  • *    Get current list of cookies
    
  • *    @access public
    
  • *    @return array
    
  • */
    
  • public function getCookies()

  • {

  •    return $this->user_agent->getCookies();
    
  • }

  • /**

  • *    Import a list of cookies
    
  • *    @access public
    
  • *    @param array
    
  • */
    
  • public function setCookies(array $lstCookies)

  • {

  •    return $this->user_agent->setCookies($lstCookies);
    
  • }

  • /**

    • Parses the raw content into a page.
    • Will load further frame pages unless frames are disabled.

diff --git a/cookies.php b/cookies.php
index ed25d08..dfff5d9 100644
--- a/cookies.php
+++ b/cookies.php
@@ -288,6 +288,16 @@ class SimpleCookieJar
}

 /**
  • *    Return a list of the current cookies
    
  • *    @access public
    
  • *    @return array
    
  • */
    
  • public function getCookies()

  • {

  •    return $this->cookies;
    
  • }

  • /**

    • Finds a matching cookie to write over or the first empty slot if none.
    • @param SimpleCookie $cookie Cookie to write into jar.
      diff --git a/user_agent.php b/user_agent.php
      index e35da5d..dd66057 100644
      --- a/user_agent.php
      +++ b/user_agent.php
      @@ -97,6 +97,45 @@ class SimpleUserAgent
      }

    /**

  • *    Get current list of cookies
    
  • *    @access public
    
  • *    @return array
    
  • */
    
  • public function getCookies()

  • {

  •    $lstCookies = $this->cookie_jar->getCookies();
    
  •    $aCookies = [];
    
  •    foreach($lstCookies as $oCookies) {
    
  •        $aCookies[] = [
    
  •            'name'=>$oCookies->getName(),
    
  •            'value'=>$oCookies->getValue(),
    
  •            'host'=>$oCookies->getHost(),
    
  •            'path'=>$oCookies->getPath(),
    
  •            'expiry'=>$oCookies->getExpiry(),
    
  •        ];
    
  •    }
    
  •    return $aCookies;
    
  • }

  • /**

  • *    Import a list of cookies
    
  • *    @access public
    
  • *    @param array
    
  • */
    
  • public function setCookies(array $lstCookies)

  • {

  •    foreach($lstCookies as $aCookies) {
    
  •            $this->cookie_jar->setCookie(
    
  •            $aCookies['name'],
    
  •            $aCookies['value'],
    
  •            $aCookies['host'],
    
  •            $aCookies['path'],
    
  •            $aCookies['expiry']
    
  •        );
    
  •    }
    
  • }

  • /**

    • Reads the most specific cookie value from the browser cookies.
    • @param string $host Host to search.
      `

replace network_confirm scripts with one request mirror script

We can remove some lines of code by de-duplicating the network_confirm.php code.
My suggestion is to use one central script for request mirroring.
The idea is to build a JSON response and use array/object access in tests.
(Basically a note for myself, before the idea gets lost.)
Quick draft:

$url = 'http://';
if (isset($_SERVER['HTTPS'])) {
    $url = 'https://';
}
$url .= "{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
if ($_SERVER['QUERY_STRING']) {
    $url .= "?{$_SERVER['QUERY_STRING']}";
}
$request = array(
    'body' => file_get_contents('php://input'),
    'headers' => getallheaders(),
    'origin' => $_SERVER['REMOTE_ADDR'],
    'method' => $_SERVER['REQUEST_METHOD'],
    'params' => array(
        'get' => $_GET,
        'post' => $_POST,
    ),
    'url' => $url,
);
header('Content-Type: application/json');
echo json_encode($request);

Access current test name from skip() and/or setUp()?

I know that we can use getTests() to get a list of all tests in a UnitTestCase, but I haven't been able to figure out if it's possible to access the test/method that's currently being run, setup, or checked for skipping.

assertText and <title>

Hi,
I cannot check for the name(title) of an object. Say it is displayed as <h1> on the web page, but again the string is used within the <title> tag. In page->getText() the string can found twice accordingly. What I would need is to restrict the extraction of text on the part of the page in order to test <title> and <h1> separately. Just put this here. Is no major thing.
Henri

Thank you!

I'm sorry to open a new issue for this, but I just wanted to take a moment to say "thank you" for Simpletest. Several years ago, I took over a large, procedural, ecommerce project and I briefly experimented with PHPUnit before giving up because I couldn't get it running in our system and with our server because of some of our design and technical limitations. Flash forward to a few weeks ago, when I stumbled upon Simpletest. Some quick research made it look more flexible than PHPUnit and it could run tests on our server via a browser. Sure enough, in just a couple of days I had it set up and was at about 15-20% coverage. Incredible!

All of our code is still being run via require and require_once statements, and Simpletest made it ... well, simple ... or at least as simple as possible ... to setup some global variables, require a single script or file, and then check assertions on the side effects or global variables that the require script left behind. Now, after just a week or so, we're at over 50% coverage and that is quickly climbing.

So: Thank you! Danke! Merci!

Unable to click a button.

I am using a browser class and unable to click the following button

input type="button" class="but" name="valid" value="Validate Form" onclick="return myclick()" style="align:center"

I try as -
$browser = new SimpleBrowser();
$browser->clickSubmitByName('valid');

Unable to click submit when there is onclick tag

$browser->clickSubmit("Submit");
or
$browser->clickSubmitByName("submitAction");

is not working on the following code -

<input type="submit" value="Submit" name="submitAction" onclick="return validate()">

Eclipse. Dynamic method called as static

Location:
simpletest/eclipse.php
EclipseReporter::escapeVal($output) . '"}'); (at line 303)

            $result = $this->listener->write('{status:"info",message:"' .
                                              EclipseReporter::escapeVal($output) . '"}');

Problem:
Dynamic method called as static

Pull request:
#3

release 1.01

Hey guys, I'm needing the simpletest release 1.01, 'Cauz using cakephp 1.3. This framework uses simpletest 1.01 (Yeap, i know :S) and i'm trying to make composer.json with simpletest but i didnt find this version.

Example simpletest for psr-4

Hello,

I look for a example of simpletest with namespaces.
I'm a beginner in unit testing.
How can help ?

Your sincerly

Stephan

Still alive?

Is this project still alive? I ask because the linked website is broken and therefore no documentation is available.

If it is still alive:

  • simpletest.org should be brought back to life
  • or an action should be added to render and deploy documentation to gh pages
  • and of course code base should be updated to support recent php versions

It it is not alive:

  • the project should be archived
  • all links to simpletest.org should be removed

wrong mime while uploading images

Recently I wrote a test for web form which supports file uploads (with use of common file input method).
At first please note, the form submitted in real browsers works as expected.

The same page submitted under WebTester, reports wrong mime of uploaded files.
I mean, the field $_FILES['somefile']['type'] contains 'application/octet-stream' instead of 'image/jpeg'.
In the meantime function mime_content_type($_FILES['somefile']['tmp_name']) returns proper and expected jpeg mime.

Question is, could it be SimpleTest related issue or rather environment related one? Before providing test case for the issue I would rather ask first. Maybe you will just know the answer.

BTW I'm using SimpleTest from time to time for a few years right now. And I'm still amazed at SimpleTest abilities. Thank you

TODO: Switch to HTTP1.1?

I put this up as I encountered a web page, whos content was sliced into chunks. This comes with HTTP/1.1 and its header "Transfer-Encoding: chunked". The chunks start with a hexadecimal number for their size and a "0" for the last chunk. With "echo $this->get(..);" you will see them. Chunks and HTTP/1.1 is a general behaviour these days.

Simpletest uses "GET /mypage.php HTTP/1.0" in http.php telling a server it will not understand the "Transfer-Encoding: chunked" header. That is why I should NOT have seen any chunked content.

I tested with 5 servers today. Two of them sent me chunked content. As I am not into (Apache) server configuration I cannot say much to why it was not handled.
https://httpd.apache.org/docs/2.2/de/env.html
One can always set the "Content-Lenght: 1234" header in the application itself, which whould prevent servers (e.g. Apache) from chunking.

Another way is to enable Simpletest to handle HTTP/1.1 protocol. That may be more an effort than just the chunked content. Here is some info about how much work it is to dechunk:
http://stackoverflow.com/questions/10793017/how-to-easily-decode-http-chunked-encoded-string-when-making-raw-http-request

I guess in the very long run Simplettest cannot stay with HTTP/1.0. So its about selecting information already about how to go that way.

AssertEqual bug

Hi. I've been making some PHP recently and I found a bug using SimpleText; here's the way to reproduce it.

class TestBuggy extends UnitTestCase {
    function testShouldBeFalse() {
        $this->assertEqual(True, 3);
    }
}

The code compilates and returns no error, while it should.
Regards,

Please support cookie/session

The following is the web test post request header, please bring a cookie in each request, otherwise can not keep session
----Translation from Google translation

HTTP/1.1 200 OK
Date: Wed, 20 Sep 2017 10:01:08 GMT
Server: Apache/2.4.27 (Debian)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Length: 105
Connection: close
Content-Type: application/json; charset=utf-8

cookies don't work between subdomains

Hello
It common to to set a cookie for all subdomains by setting DOMAIN parameter of cookie to:
.mydomain.com

Unfortunately it doesn't work under WebTester. For example a cookie set for www.mydomain.com is not accessible for subsequently opened page: www.subdomain.mydomain.com.
I've confirmed, cookies work under WebTester while opening pages from the same subdomain as cookie was set.

This issue appear in v1.10 as well as 1.1.8-dev

with regards

Integration with NetBeans

Do you have any plans to integrate Simpletest with NetBeans?
Currently I have no idea about requirements of such integration. For sure it all about writing NB plugin which can process simpletest output.

with regards

Mocking interfaces with class definitions in arguments is broken

Hi,

used an older version of simpletest and upgraded now to the master as I required namespaced mocks (great btw).
Unfortunately it seems that interfaces having methods defining the class type in arguments cannot be mocked any more. Assuming a class:

interface PluginFactory
{
function setConfig(Config $config);
}
produces this error:

Declaration of MockPluginFactory::setConfig() must be compatible with PluginFactory::setConfig(Config $config)

Best regards,

Philipp

Late Constructor Calls

One of the side effects of using the named constructors (<= 1.1.6) was that it was possible to call the __construct method, late. The use case for this is for setting/adjusting instance variables on your mock prior to the constructor logic being run. With the move to mocks that use the __construct method this is no longer possible.

We're working around that for now with a custom MockGenerator that injects the following function into all mocks:

function __constructor() {
    call_user_func_array('parent::__construct', func_get_args());
}

This gives us a predictable way to late call the underlying __construct on any type of mock. Would you be interested in a PR for this functionality in core?

dumper->clipString() is multibyte safe?

Hi. I guess not. It will cut UTF-8 text in parts, which may contain invalid "characters" at the end. A part of a multibyte characters. Comes in rare cases only... if you work with "รค,รŸ,.." or else. Simply use mb_strlen, mb_substr.

Documentation translation

Firstly, thank you for providing this project to make the PHP unit testing easily.
When I refer the documentation, it only has the English version now.
If possible, I can provide the traditional Chinese version for this project.
I will also publish the tutorial post on my blog.
How can I contribute the documentation?
Thanks.

PHP 7.2: Spurious test errors due to legacy constructors

Deprecation warnings from the old-style constructor used in MockGenerator::extendClassCode:

Unexpected PHP Error [Methods with the same name as their class will not be constructors in a future version of PHP; HTMLPurifier_DefinitionTestable has a deprecated constructor] severity [8192] in [simpletest/simpletest/mock_objects.php(1429) : eval()'d code line 1]

how to click href when there is nowrap

I was trying to click the href for the following code

<td  align="right" nowrap="nowrap">
<a href="newaccout.do">My Details</a>
</td>

$browser->click("My Details");
and it redirect to another page. So I am unable to process next.

composer warning: Ambiguous class resolution; file for autoloading is chosen at random

Warning: Ambiguous class resolution, "SimpleReflection" was found in both "vendor/simpletest/simpletest/reflection_php4.php" and "vendor/simpletest/simpletest/reflection_php5.php", the first will be used.

Composer seems to iterate in filesystem order, so this class effectively gets chosen at random on each distinct installation, although the php5 variant is the correct one in my environment.

I don't think this makes a difference (the class isn't actually autoloaded, so if the wrong one was in the autoloader, nothing bad happens) unless client code accidentally triggers the autoload before SimpleTest gets a chance to do its own direct loading. Still, I would like the warning to be fixed.

In fact, I think the php4 file can just be deleted. composer.json and the bundled docs both say 1.1+ are PHP5-only, and I can't find anywhere that would load the php4 variant.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.