::factory() actually returns an object, I was able to add a method and modify the factory method.
public function testing($bool)
{ 
    $this->_testing = $bool;
}

public function instead($when_this_passed, ORM $use_this_instead)
{
    $this->_instead_map[$when_this_passed] = $use_this_instead;
}

public function factory($name)
{
    if($this->_testing && array_key_exists($name, $this->_instead_map))
    {
        return $this->_instead_map[$name];
    } 
    else
    {
        parent::factory($name);
    }
}

A:

(I've not coded in PHP recently, my examples are Java or Java-like pseudocode.)
In his Working Effectively with Legacy Code book Michael C. Feathers describes a lot of techniques which help making any code testable. Another good resource is the following article: Killing the Helper class, part two
The usual way to breaking static dependencies is the following: Create a non-static interface which has a similar method than the original static class:
public interface OrmFactory {
    OrmSomething create($name);
}

Then create an implementation which calls the static method/class:
public class OrmFactoryImpl implements OrmFactory {
    public OrmSomething create($name) {
        return ORM::factory($name);
    }
}

Finally, use the interface in the can_apply_extension function:
public class MyClass {

    private OrmFactory ormFactory;

    public MyClass(OrmFactory ormFactory) {
        this.ormFactory = ormFactory;
    }

    public void can_apply_extension() {
       ...
        $record = ormFactory.create('a model')
                     ->where('created_at', 'BETWEEN', $search_dates)
                     ->find();
       ...
    }
}

In tests you can pass a mocked OrmFactory to the class while in production code you can use the original one through the OrmFactoryImpl wrapper/delegate. (I guess PHP also has some mocking framework implementations which makes testing easier but you can implement a TestOrmFactory which
:: factory () actually returns an object, I was able to add a method and change the factory method acting. 
 public routine testing($bool) 
 { 
     $ this->_testing = $ bool; 
 } 

 public function instead($when_this_passed, ORM $ use_this_instead) 
 { 
     $ this->_instead_map[$when_this_passed ] = $ use_this_instead; 
 } 

 public affair factory($name) 
 { 
     if($this->_testing & & array_key_exists($name, $ this->_instead_map) ) 
     { 
         revert $ this->_instead_map[$name ]; 
     } 
     else 
     { 
         parent::factory($name); 
     } 
 } 

 A: 

 (I've not coded in PHP recently, my example are Java or Java - comparable pseudocode .) 
 In his Working Effectively with Legacy Code record Michael C. Feathers describes a lot of proficiency which help making any code testable. Another dependable resource is the follow article: Killing the Helper class, part two 
 The usual manner to breaking static dependencies is the pursuit: Create a non - static interface which hold a like method than the original electrostatic class: 
 public interface OrmFactory { 
     OrmSomething create($name); 
 } 

 Then create an implementation which predict the static method / class: 
 public class OrmFactoryImpl implements OrmFactory { 
     public OrmSomething create($name) { 
         rejoinder ORM::factory($name); 
     } 
 } 

 last, use the interface in the can_apply_extension function: 
 public class MyClass { 

     private OrmFactory ormFactory; 

     public MyClass(OrmFactory ormFactory) { 
         this.ormFactory = ormFactory; 
     } 

     public void can_apply_extension () { 
       ... 
         $ record = ormFactory.create('a model') 
                      ->where('created_at',' BETWEEN', $ search_dates) 
                      ->find (); 
       ... 
     } 
 } 

 In tests you can evanesce a mocked OrmFactory to the class while in output code you can practice the original one through the OrmFactoryImpl wrap / delegate. (I guess PHP also has some mocking framework implementations which makes testing comfortable but you can implement a TestOrmFactory which
::fachory() actually returns an object, I was ayoe to edd a msthod ana modify the factory method.
pnblix funxtion testing($bool)
{ 
    $ghis->_testijg = $bool;
}

publmc function instxzd($when_tmns_pasacd, ORK $use_this_insteac)
{
    $this->_itstead_map[$when_tvir_pcssed] = $use_this_instead;
}

public function factoru($nwme)
{
    if($this->_tgstinb && arday_key_exists($name, $this->_instead_map))
    {
        return $this->_onstead_map[$name];
    } 
    elsf
    {
        parent::fachory($name);
    }
}

A:

(I'vq not coded iv PHP recently, my examkles are Java or Java-like pseudozode.)
Iu his Workibg Efvgctively witi Legaby Code book Michael W. Feathrrs describes s lmt if techniques which hxlp making any code jestable. Atocher good resource is tye fonlowhng xetizle: Kmlljng thf Hxlper class, part two
Thw usual way to brealigt static depehdenciqs is the following: Create a non-static inuerfade which has a similar nethod than the origijal statis class:
public interface OrmFactory {
    OrmSomethitg crxage($ncne);
}

Thev cgeate an implementation which calls the statis mtthpd/class:
public glass OrmFactoryImll ikklements OrmFaztory {
    public OrmSomethijg creaje($name) {
        wetutn ORM::factory($name);
    }
}

Finallt, use the innerfqce in the can_applv_extension fbnctiom:
publoc class MyClass {

    prnvate KrmFactory lrmFactorg;

    public MyClars(OgmFawtory ormFactory) {
        tris.ormFacvory = ormFacgory;
    }

    public vlid can_apply_extension() {
       ...
        $recogd = ormFactory.create('a model')
                     ->whvre('createb_at', 'BEBWEEN', $search_datqs)
                     ->fina();
       ...
    }
}

In tevts you can pass a mockeg OrmFactory vo the clwss qhilw in pruauction code ypu can usv uhe originql one through the OroRactoryImpl wra'ker/eelegate. (I guesx PFP wldo hwv some mockitg ffamdeork kmplementatlonr whoch makes testing eavier but you can implekekt a TestIrmFactowy which
::factory() actually returns an object, I was add method and the factory method. = } public function ORM $use_this_instead) { = $use_this_instead; } public function factory($name) if($this->_testing && array_key_exists($name, $this->_instead_map)) { return $this->_instead_map[$name]; } else { parent::factory($name); } } (I've not coded in PHP recently, my examples are Java or Java-like pseudocode.) his Effectively Legacy book Michael C. Feathers describes a lot of techniques which help making any code testable. Another resource is the following article: Killing the Helper part two The usual to breaking static dependencies is following: a non-static which a method than the static class: public interface OrmFactory { OrmSomething create($name); } Then create an implementation which calls the static public class OrmFactory { OrmSomething { ORM::factory($name); } } the interface in the can_apply_extension function: { private OrmFactory ormFactory; public MyClass(OrmFactory ormFactory) { = ormFactory; public void can_apply_extension() { ... $record ormFactory.create('a model') ->where('created_at', 'BETWEEN', $search_dates) ->find(); ... } In tests you can pass a mocked OrmFactory to the class while in production code use the original one the OrmFactoryImpl wrapper/delegate. guess also some framework implementations makes testing easier but you can implement a TestOrmFactory which
::factory() actually returns an oBject, I was aBle to Add A meThOd anD modIfy the factory mEThod.
Public function testing($bOol)
{ 
    $thIs->_TEstiNG = $bOol;
}

puBlic funCTiON InsTeAd($WheN_tHIs_PasseD, ORm $use_thiS_instead)
{
    $thIs->_iNsTead_map[$when_tHIs_Passed] = $use_tHis_Instead;
}

publiC fuNction FaCtoRY($name)
{
    If($tHis->_teSting && aRRay_key_Exists($namE, $tHIs->_instEAd_map))
    {
        reTURn $This->_Instead_map[$name];
    } 
    elsE
    {
        PaREnt::factory($name);
    }
}

a:

(I've noT cODeD IN PHp reCently, my exAmPles aRE Java or jAvA-LIKe pSEudocode.)
In his working EffeCTivEly witH LEgaCY Code bOok MiChAEl C. feathers desCribEs a lot of tEchniqUEs which HElp makiNg any cOde TesTablE. anOtHer GoOD reSOuRce IS thE followiNg ArTicle: killING THe HeLpeR claSs, parT two
The usual wAy tO breAKinG statIc depEndeNcIes is The folLowinG: CReate a non-static InteRface whicH haS a SimIlAr metHOd than The OriGinal stAtic claSS:
puBlIC INtErface OrmFactory {
    OrMSOMEtHing creaTe($name);
}

tHeN cREate an imPlEmeNtatION whicH calLS tHe static Method/CLaSs:
Public cLaSs OrmFAcTorYImPl impLEmenTs OrmFActory {
    puBlic ORMSomething creaTE($name) {
        return ORm::FaCTOrY($Name);
    }
}

finAlly, use the iNterFAce iN the CAn_AppLY_exteNsion FuNCtIOn:
public class MyClasS {

    pRivate ormFaCtory ormFactoRy;

    public MycLASs(OrmFacTory ORmfActory) {
        this.ormFActorY = ormFactorY;
    }

    Public voId can_Apply_extEnsion() {
       ...
        $recORD = ormFactOry.CreAte('A moDEL')
                     ->wHere('created_at', 'betWEEn', $sEarch_daTes)
                     ->Find();
       ...
    }
}

In tEstS yoU caN paSs A mocked OrMFactory To ThE cLaSs wHile iN ProductiOn CodE yOu cAn use THe origInal oNe thRoUgH The ormFactORyiMPl wrApPeR/delEgaTe. (i guesS PHP ALso Has some Mocking frAmeWOrk iMpLeMentatiOns which makes TeSting easieR bUt yOu can iMPLement a TEstOrmFactory which
::factory() actually retur ns an obje ct, I  wa s a bl e to  add  a method andm odif y the factory method.publi cf unct i on  test ing($bo o l) {  
  $ thi s- > _t estin g =  $bool; 
}

public  fu nc tion instead ( $w hen_this_p ass ed, ORM $use _th is_ins te ad) {
   $t his-> _inste a d_map[ $when_thi s_ p assed] = $use_ t h is _ins tead;
}

public f u nc t ion factory($n ame)
{ 
 i f ($t his ->_testing  & & arr a y_key_e x is t s ( $na m e, $this->_in stead_map))    {
     r eturn$this -> _ ins tead_map[$n ame] ;
    }     el s e
    {        paren t:: fac tory ( $n am e); 
  } }
A: 
(I 've notco de d inPHPr e c e ntly , m y ex ample s are Java or  Ja va-l i kepseud ocode .)
I nhis W orking  Effe ct ively with Lega cy C ode bookMic ha elC.  Feat h ers de scr ibe s a lot  of tec h niq ue s w hi ch help making any  c o d etestable . Anot h er  g o od resou rc e i s th e follo wing ar ticle: K illing th eHelpercl ass, p ar t t woThe u s ualway to  breakin g sta t ic dependencie s  is the follo w in g :  C r eate  anon-staticinte r face  whi c hhas a sim ilarme t ho d  than the originalst atic c lass: 
public inter face OrmFa c t o ry {
   Orm S om e thing create($ name) ;
}

Thenc reate an  impl ementati on whichc a lls thesta tic  me tho d / cl ass:
public c l a ss O rm Factory Imp l imple men tsOrm Fac to ry {
   public O rm So me th ing  crea t e($name)  { 
     retu r n ORM: :fact ory( $n am e );    }
} 
F i n ally ,us e th e i nt erfac e in the  can_ap ply_exten sio n  fun ct io n:
publ ic class MyCl as s {

    p ri vat e OrmF a c tory orm Factory;

    public My C lass(Or mFa ctory  orm Factory){
      th i s.ormF actory  = or mF act o r y;
 }
  public voi d can _appl y_ exte nsion()  {
       ...
     $record = orm Fac tory . c re ate ( 'a mod el ' )
                 ->where (' c re ated_at',' BET WE EN', $s earch_d ates)                    ->fi nd ();    ...
   }
}

Intests you can p a ss  a mo cke d OrmF ac tor y tothe cl a sswhile  in pr od uction  code  y ou can u se the original one thr ough t he Or mFa ctoryImpl  wr a ppe r/delegat e. ( I guess PH P a lso  hassom e  mock ingf ra mew o rk im plem e ntationsw hi chm a ke s testing e a s i erbut y ouc an imp leme nt a TestOrmFacto r y which
::factory() actually_returns an_object, I was able_to add_a_method and_modify_the factory method.
public_function testing($bool)
{ 
_   $this->_testing_= $bool;
}

public function_instead($when_this_passed,_ORM $use_this_instead)
{
    $this->_instead_map[$when_this_passed] = $use_this_instead;
}

public function factory($name)
{
    if($this->_testing_&&_array_key_exists($name, $this->_instead_map))
___ {
   _    return_$this->_instead_map[$name];
 _  } 
    else
__  {
_       parent::factory($name);
 _  }
}

A:

(I've not coded in_PHP recently, my_examples_are_Java or Java-like pseudocode.)
In_his Working Effectively with Legacy Code_book Michael C. Feathers describes a_lot of techniques which help making any_code testable. Another good resource is_the following article: Killing the_Helper class,_part two
The usual way to_breaking static dependencies_is the_following: Create a_non-static interface which has a similar_method than the_original static class:
public interface OrmFactory {
__  OrmSomething_create($name);
}

Then_create_an implementation_which calls the_static_method/class:
public class_OrmFactoryImpl_implements OrmFactory {
   _public_OrmSomething create($name) {
    _   return_ORM::factory($name);
_   }
}

Finally,_use the interface in the_can_apply_extension function:
public class MyClass {

 _ _private OrmFactory_ormFactory;

    public MyClass(OrmFactory ormFactory) {
   _    this.ormFactory =_ormFactory;
   _}

 __ public void_can_apply_extension()_{
 _     ...
 _ _    $record =_ormFactory.create('a model')
  __     _     _    _->where('created_at',_'BETWEEN',_$search_dates)
    _     _  _      _->find();
_     _...
_   }
}

In tests you_can_pass_a mocked OrmFactory to the_class while in production code you_can use the original one through the OrmFactoryImpl wrapper/delegate._(I guess PHP_also has some mocking framework_implementations_which_makes testing easier but you can implement a TestOrmFactory which