0

I have the following class:

class Validator {
 public function __construct($file){                
  $errors = $this->errors($file_array[CSV]['errors']);
  }
 public function errors_func($errors){
  if($errors != 0){
   throw new Exception('Error Uploading');
  }
 }
}

I'm attempting to target the errors_func() function directly through my test script without the need to first invoke the constructor. The PHPT test script can be seen below:

--TEST--
check_mime() function - A basic test to see if check mime works. :)
--FILE--

    <?php
    require_once('my/path');
    $valid = new Validation;
    $re = $valid->errors_func('1);
    var_dump($re);
    ?>
    --EXPECT--
    bool(true)

As you would expect though the test script fails becuase a parameter is expected when the object of the class is created. Is there a way to create an object of the Validation class without needing to pass an argument to the class __constructer?

Liam Fell
  • 1,308
  • 3
  • 21
  • 39

1 Answers1

0

I've found a solution to this by using ReflectionClass. The new test script would look like this:

--TEST--
check_mime() function - A basic test to see if check mime works. :)
--FILE--

    <?php
    require_once('my/path');
    $valid = new ReflectionClass('Validator');
    $valid_direct = $valid->newInstanceWithoutConstructor();
    $re = $valid_direct->errors_func('1);
    var_dump($re);
    ?>
    --EXPECT--
    bool(true)
Liam Fell
  • 1,308
  • 3
  • 21
  • 39