SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42
  1. #26
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by been
    Apparently not...

    I've never even considered something like
    PHP Code:
    require_once 'modules///admin///config.php'
    would actually work...
    yes and no. Yes from the perspective of the code handles multiple slashes fine and will load the code, No from the perspective of if you hit another require_once with a different number of slashes, but still pointing to the same file, it will attempt to load the file again

  2. #27
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There isn't a problem with how the pathnames are worked out either. There are no reports of non file fetchs for that matter. Take a look at this, as one example

    Code:
    // had to do a var_dump() instead as sitepoint reported too many smillies??
    object(PageActionHandler)[1]
      protected 'id' => 'page'
      protected 'children' => 
        array
          'body' => 
            object(BodyActionHandler)[2]
              protected 'id' => 'body'
              protected 'children' => 
                array
                  'breadcrumb' => 
                    object(BreadcrumbActionHandler)[3]
                      protected 'id' => 'breadcrumb'
                      protected 'children' => 
                        array
                          empty
                      public 'path' => 'admin/body/breadcrumb'
              public 'path' => 'admin/body'
          'menu' => 
            object(MenuActionHandler)[4]
              protected 'id' => 'menu'
              protected 'children' => 
                array
                  'childmenu1' => 
                    object(ChildMenu1ActionHandler)[5]
                      protected 'id' => 'childmenu1'
                      protected 'children' => 
                        array
                          empty
                      public 'path' => 'common/menu/childmenu1'
                  'childmenu2' => 
                    object(ChildMenu2ActionHandler)[6]
                      protected 'id' => 'childmenu2'
                      protected 'children' => 
                        array
                          'childmenu2_1' => 
                            object(ChildMenu2_1ActionHandler)[7]
                              protected 'id' => 'childmenu2_1'
                              protected 'children' => 
                                array
                                  empty
                              public 'path' => 'common/menu/childmenu2/childmenu2_1'
                      public 'path' => 'common/menu/childmenu2'
              public 'path' => 'common/menu'
    Look at the property $path for example for each element. Just as you'd expect, so in all probabilities, it is an issue with Simple Test. It is version 1.0RC1 of Simple Test that I'm using on my Desktop at the moment if that is any help to anyone

    PHP Code:
    define'SIMPLE_TEST''../tools/simpletest/' );
        require_once( 
    SIMPLE_TEST.'reporter.php' );
        require_once( 
    SIMPLE_TEST.'unit_tester.php' );
        
        class 
    TestOf extends UnitTestCase {
            public function 
    __construct() {
                
    parent::__construct'Test: Of' );
            }
            
            public function 
    testIsActionHandler() {
                
    $handler = new PageActionHandler'admin/' );
                
    $ref = new ReflectionClass$handler );
                
    $interfaces $ref -> getInterfaces();
                
                
    $this -> assertTruearray_shift$interfaces ) -> getName(), 'IComposite' );
                
    $this -> assertTruearray_shift$interfaces ) -> getName(), 'IActionHandler' );
            }
            
            public function 
    testIsNotChildless() {
                
    $handler = new PageActionHandler'admin/' );
                
    // check that we have 2 children
                
    $children $handler -> getChildren();
                
    // first child, body
                
    $body array_shift$children );
                
    // second child, menu
                
    $menu array_shift$children );
                
    //
                // with this unit test, the following throws an error
                // that is rubbish as it is perfectly legal; the child
                // exits!! WTF?? Marcus??
                
    $this -> assertTrue$body -> getId(), 'body' );
                
    //
                // doing this check outside the testing works perfectly
                // so draw your own conclusions.
            
    }
        }
        
        
    $test = new TestOf();
        
    $test -> run( new HtmlReporter() ); 

  3. #28
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $array = array( 'id' => '1''firstname' => 'les''lastname' => 'quinn' );
        
    $serialised serialize$array );
        
    file_put_contents'array.php'$serialised );
        
        
    define'SIMPLE_TEST''../tools/simpletest/' );
        require_once( 
    SIMPLE_TEST.'reporter.php' );
        require_once( 
    SIMPLE_TEST.'unit_tester.php' );
        
        class 
    ASimpleTestOfSimpleTest extends UnitTestCase {
            public function 
    __construct() {
                
    parent::__construct'Test: A Simple Test Of Simple Test' );
            }
            
            public function 
    testDummyArray() {
                
    $array = array( 'id' => '1''firstname' => 'les''lastname' => 'quinn' );
                
    $this -> assertTruein_array1$array ) );
            }
            
            public function 
    testSerialisedArrayFetch() { 
                
    $array unserializefile_get_contents'array.php' ) );
                
    $this -> assertTruein_array'les'$array ) );
            }
            
            public function 
    testGetArrayFromRequireFile() {
                require_once( 
    'non-serialised-array.php' );
                
    $this -> assertTruein_array'les'$array ) );
            }
            
            public function 
    testRequiredArrayFetch() {
                
    // this fails with an error
                
    require_once( 'non-serialised-array.php' );
                
    $this -> assertTruein_array'les'$array ) );
            }
            
            public function 
    testRequiredArrayFetchLoop() {
                require_once( 
    'non-serialised-array.php' );
                foreach( 
    $array as $key => $value ) {
                    
    // this test throws exactly the same error that i
                    // got with my other scripts
                
    }
            }
        }
        
        
    $test = new ASimpleTestOfSimpleTest();
        
    $test -> run( new HtmlReporter() ); 
    PHP Code:
    // required file
    $array = array( 'id' => '1''firstname' => 'les''lastname' => 'quinn' ); 
    Report:

    Code:
    1/1 test cases complete: 3 passes, 1 fails and 2 exceptions.
    Make what of it, if you will but there is definitely a bug there somewhere. I've wasted the last day trying to work with this, and it's cost me money, lack of sleep and now I've got a -BEEP- of a headache.

    Marcus, if at some point you get around to reading through this thread, I'd very much like to see some input from you.

  4. #29
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you
    PHP Code:
     require_once( 'non-serialised-array.php' ); 
    more than once in a php script and expecting it to work?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  5. #30
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah Got a habit of using that all the time Since you've made that point Jason, it's a point I'll not forget in a hurry, thanks

  6. #31
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still doesn't solve the original problem though...

  7. #32
    SitePoint Addict been's Avatar
    Join Date
    May 2002
    Location
    Gent, Belgium
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    No from the perspective of if you hit another require_once with a different number of slashes, but still pointing to the same file, it will attempt to load the file again
    Kinda puts "once" in a different perspective
    Per
    Everything
    works on a PowerPoint slide

  8. #33
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed your require_once's to require and misspelled "serialized" in your file name the same as your code, then I get:

    Code:
    sweatje@gentoo  $ php test_array.php
    Test: A Simple Test Of Simple Test
    OK
    Test cases run: 1/1, Passes: 4, Failures: 0, Exceptions: 0
    sweatje@gentoo  $ php -v
    PHP 5.0.3 (cli) (built: May  3 2005 03:50:13)
    Copyright (c) 1997-2004 The PHP Group
    Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
        with Xdebug v1.3.2, Copyright (c) 2002, 2003, by Derick Rethans

  9. #34
    SitePoint Addict been's Avatar
    Join Date
    May 2002
    Location
    Gent, Belgium
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Still doesn't solve the original problem though...
    Smells like you're calling Handle::resolve() in different tests on the same file?
    Maybe you should attach the test case?
    Per
    Everything
    works on a PowerPoint slide

  10. #35
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, that is not it either

    PHP Code:
    define'SIMPLE_TEST''../tools/simpletest/' );
        
        require_once( 
    'handle.class.php' );
        require_once( 
    'action-handler.class.php' );
        require_once( 
    SIMPLE_TEST.'reporter.php' );
        require_once( 
    SIMPLE_TEST.'unit_tester.php' );
        
        class 
    Test extends UnitTestCase {
            public function 
    __construct() {
                
    parent::__construct'Test' );
            }
            
            public function 
    testOne() { // pass
                
    $handler = new PageActionHandler'admin/' );
                
    $ref = new ReflectionClass$handler );
                
    $interfaces $ref -> getInterfaces();
                
                
    $this -> assertTruearray_shift$interfaces ) -> getName(), 'IComposite' );
                
    $this -> assertTruearray_shift$interfaces ) -> getName(), 'IActionHandler' );
            }
            
            public function 
    testTwo() { // fail
                
    $array = array( 'body''menu' );
                
    $handler = new PageActionHandler'admin/' );
                
    $this -> assertTrue$handler -> hasChildren() );
            }
        }
        
        
    $test = new Test();
        
    $test -> run( new HtmlReporter() ); 
    Code:
    1/1 test cases complete: 2 passes, 1 fails and 0 exceptions.
    I'm going to have to leave this but apparantly I can't test my composite structures, so I'll just have to resort to the old fashioned method

  11. #36
    SitePoint Addict been's Avatar
    Join Date
    May 2002
    Location
    Gent, Belgium
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Nope, that is not it either
    Sorry, bad wording on my part, I was actually trying to point out the fact that somewhere require_once() was called on the same file between different tests...

    Although require_once() isn't called from Handle::resolve(), it is called from the constructor of BaseActionHandler, if I change the require_once() into require() there, I have a green bar...
    Per
    Everything
    works on a PowerPoint slide

  12. #37
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was actually trying to point out the fact that somewhere require_once() was called on the same file between different tests...
    Now I see where your going, even though the REQUIRE_ONCE is doing it's job from the perspective of the script, but with the tests, it is duplicated as in each of the tests.

    Well, in that regards that could cause some problems, so I'll take another look at it, but that makes no sense either, does it?

    It means that with unit tests, it renders REQUIRE_ONCE inoperable. The probability of one file being REQUIREd more than once during the recursion of my script, is pretty much remote, but why should I use REQUIRE to satisfy unit testing?

    One way around this, and still to be able to use REQUIRE_ONCE in that case, is just to have the one test, and for other tests, create a new test class, which is nonsense as well

  13. #38
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like testing is forcing you to think about what you are coding, and making your code testable, which is one of the goals of doing the testing. We just showed in your "A Simple test of SimpleTest" code that you were abusing require_once for a simple array include because of a "habit". I think this testing is showing you a bad habit you need to change.

  14. #39
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There may be a point in what your saying,

    PHP Code:
    require_once( '../tools/simpletest/reporter.php' );
        require_once( 
    '../tools/simpletest/unit_tester.php' );
        
        class 
    TestActionHandlers extends UnitTestCase {
            public function 
    __construct() {
                
    parent::__construct'Test: Action Handler (Renderer)' );
            }
            
            public function 
    TestPattern() { // pass
                
    $request = new RequestHandler( new HttpRequest() );
                
    $response = new Response$request );
                
    $handler = new PageActionHandler'admin/' );
                
    $handler -> accept$response );
                
    ob_start();
                
    $response -> render();
                
    $html ob_get_clean();
                
    $this -> assertWantedPattern'/This is the PAGE fragment/'$html );
            }
        }
        
        
    $test = new TestActionHandlers();
        
    $test -> run( new HtmlReporter() ); 
    But it doesn't in the short term, make my life any easier. Btw Jason, any ideas on how you'd Mock out the RequestHandler, HttpRequest and Response classes?

    PHP Code:
    class RequestHandler extends BaseRequestHandler {
    public function 
    __constructHttpRequest $http_request ) { ... 
    PHP Code:
    class Response implements IResponse {
            private 
    $buffer;
            private 
    $template;
            public 
    $request_handler;
            
            public function 
    __constructIRequestHandler $request_handler ) { 
    Any ideas would be most welcome, thanks

  15. #40
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dr. Livingston, here's a useful rule of thumb:

    If the file you're including (or requiring) contains class or function definitions to be called and used elsewhere in the script, use *_once(). Otherwise, if the file contains code which is to be evaluated and execute immediately, use plain include or require by any means. Also, avoid mixing definitions and executable code in the same included file if at all possible.

  16. #41
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the advice, I'll take it under advicement, but what I'm really thinking is that in an event such as this, I'll just have the one test per class and leave it that.

    Just makes more sense to me therefore, just to group the tests, and let the whole lot run as one no?

  17. #42
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Thanks for the advice, I'll take it under advicement, but what I'm really thinking is that in an event such as this, I'll just have the one test per class and leave it that.

    Just makes more sense to me therefore, just to group the tests, and let the whole lot run as one no?
    That's right, and that's exactly the reason for my advice. This is actually the reason why there are two versions of include/require. include_once() is not some kind of an "improved" version of include() -- it has a completely different purpose.

    This is not just an advice, this is basically the only way this things can and should be done in PHP.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •